protected override void Load(ContainerBuilder builder) { Guard.Against.Null(ServiceBusConnectionStrings, nameof(ServiceBusConnectionStrings)); foreach (var connString in ServiceBusConnectionStrings) { Guard.Against.NullOrEmpty(connString.Value, nameof(connString)); var serviceBusOption = new ServiceBusOption() { ConnectionString = connString.Value, ClientMode = ClientMode.Sending, IsCompressed = isCompressed }; if (ServiceBusConnectionStrings.Count == 1) { builder.Register(c => { var serviceBusConnection = new ServiceBusConnectionStringBuilder(connString.Value); var serviceBusPersisterConnection = new DefaultServiceBusPersisterConnection(serviceBusConnection); return(new EventBusServiceBus(serviceBusPersisterConnection, serviceBusOption)); }).As <IEventBus>().SingleInstance(); } else { builder.Register(c => { var serviceBusConnection = new ServiceBusConnectionStringBuilder(connString.Value); var serviceBusPersisterConnection = new DefaultServiceBusPersisterConnection(serviceBusConnection); return(new EventBusServiceBus(serviceBusPersisterConnection, serviceBusOption)); }).Keyed <IEventBus>(connString.Key).SingleInstance(); } } }
public void Processor_ReturnProcessor() { //Arrange var sut = new DefaultServiceBusPersisterConnection(connectionString, "my-subscription"); //Act //Assert sut.Processor.Should().NotBeNull(); }
public void AdminClient_ReturnAdminClient() { //Arrange var sut = new DefaultServiceBusPersisterConnection(connectionString, "my-subscription"); //Act //Assert sut.AdminClient.Should().NotBeNull(); }
public void Dispose() { //Arrange var sut = new DefaultServiceBusPersisterConnection(connectionString, "my-subscription"); //Act sut.Dispose(); //Assert true.Should().Be(true); }
public void CreateModel_ReturnServiceBusClient() { //Arrange var sut = new DefaultServiceBusPersisterConnection(connectionString, "my-subscription"); //Act var result = sut.CreateModel(); //Assert result.Should().Be(sut.ServiceBusClient); }
public async Task StartReceiving_ProcessorIsStarted() { //Arrange var sut = new DefaultServiceBusPersisterConnection(connectionString, "my-subscription"); sut.Processor.ProcessMessageAsync += (args) => { return(Task.CompletedTask); }; sut.Processor.ProcessErrorAsync += (args) => { return(Task.CompletedTask); }; //Act await sut.StartReceiving(); //Assert sut.Processor.IsProcessing.Should().Be(true); }
protected virtual async Task InitEventBusClient(ServiceBusOption serviceBusOption) { try { //retrieve from servicebus option var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusOption.ConnectionString); var serviceBusPersisterConnection = new DefaultServiceBusPersisterConnection(serviceBusConnection); var eventBusSubcriptionsManager = new InMemoryEventBusSubscriptionsManager(); //resolve if needed using the scope //careful consider create child scope instead of passing container EventBus = new EventBusServiceBus(serviceBusPersisterConnection, eventBusSubcriptionsManager, serviceBusOption.SubscriptionName, CoreDependencyResolver.Container, serviceBusOption, CoreDependencyResolver.Container.Resolve <ILoggerFactory>()); await((EventBusServiceBus)EventBus).InitializeAsync(serviceBusPersisterConnection, eventBusSubcriptionsManager, serviceBusOption.SubscriptionName, RetryPolicy.Default); await Subscribe(); } catch (Exception ex) { Logger.LogError($"{CurrentActor} failed to init service bus client with provided service bus option subscriptionName = {serviceBusOption.SubscriptionName}", ex); throw; } }