public async Task Subscriber_ProcessTheMessageTheSecondTime_MessageMustBeRemovedFromTheRabbitMq() { //prepare IConfiguration configuration = ConfigurationHelper.ProvideConfiguration(); var exchangeName = "Subscriber_ProcessTheMessageTheSecondTime_MessageMustBeRemovedFromTheRabbitMq.exchangename"; configuration["rabbitmq:exchangename"] = exchangeName; configuration["rabbitmq:waitexchangename"] = exchangeName.Replace("exchangename", "waitexchangename"); configuration["rabbitmq:retryfactor"] = 100.ToString(); var maxretrycount = 2; IContainer container = ConfigurationHelper.ConfigureContainer(configuration); //create Subscriber var bookingCreatedSubscriberFactory = container.Resolve <ISubscriberFactory>(); ISubscriber typedSubscriber = await bookingCreatedSubscriberFactory .CreateSubscriberAsync("Subscriber_ProcessTheMessageTheSecondTime_MessageMustBeRemovedFromTheRabbitMq" + ".typedbookingcreatedconsumer", new List <string> { "*.entity.create.booking" }, maxretrycount); BookingTypedConsumer typedConsumer = new BookingTypedConsumer(1); typedSubscriber.Subscribe(SubscriptionBuilder.Create().AddDefaultSubscription(() => typedConsumer).Build()); //create Publisher var publisher = container.Resolve <IPublisher>(); string routingKey = "changetracker.entity.create.booking"; //act BookingCreated bookingCreated = new BookingCreated() { BookingName = string.Concat("Microsoft Sale", Guid.NewGuid().ToString()) }; var bookingCreatedIntegrationEvent = new IntegrationEvent <BookingCreated>() { Content = bookingCreated, EventType = "bookingcreated" }; await publisher.PublishEventAsync(bookingCreatedIntegrationEvent, routingKey); await Task.Delay(500); //check typedConsumer.ProcessedIntegrationEvent.ShouldBeEquivalentTo(bookingCreatedIntegrationEvent); typedConsumer.CountOfAttempts.Should().Be(2); container.Dispose(); }
public async Task Publisher_PublishDirectEventAsync_MessageMustBeSerializedAndCorrectlyRoutedToSpecificSubscriber() { //prepare IConfiguration configuration = ConfigurationHelper.ProvideConfiguration(); var exchangeName = "Publisher_PublishDirectEventAsync_MessageMustBeSerializedAndCorrectlyRoutedToSpecificSubscriber.exchangename"; configuration["rabbitmq:exchangename"] = exchangeName; configuration["rabbitmq:waitexchangename"] = exchangeName.Replace("exchangename", "waitexchangename"); var maxretrycount = 2; IContainer container = ConfigurationHelper.ConfigureContainer(configuration); //create Subscriber var bookingCreatedSubscriberFactory = container.Resolve <ISubscriberFactory>(); string subscriberName = "Publisher_PublishDirectEventAsync_MessageMustBeSerializedAndCorrectlyRoutedToSpecificSubscriber.typedbookingcreatedconsumer"; ISubscriber typedSubscriber = await bookingCreatedSubscriberFactory .CreateSubscriberAsync(subscriberName, (List <string>) null, maxretrycount); BookingTypedConsumer typedConsumer = new BookingTypedConsumer(0); typedSubscriber.Subscribe(SubscriptionBuilder.Create().AddDefaultSubscription(() => typedConsumer).Build()); //create Publisher var publisher = container.Resolve <IPublisher>(); //act BookingCreated bookingCreated = new BookingCreated() { BookingName = string.Concat("Microsoft Sale", Guid.NewGuid().ToString()) }; var bookingCreatedIntegrationEvent = new IntegrationEvent <BookingCreated>() { Content = bookingCreated, EventType = "bookingcreated" }; await publisher.PublishDirectEventAsync(bookingCreatedIntegrationEvent, subscriberName); await Task.Delay(200); //check typedConsumer.ProcessedIntegrationEvent.ShouldBeEquivalentTo(bookingCreatedIntegrationEvent); typedConsumer.CountOfAttempts.Should().Be(1); container.Dispose(); }
public async Task Subscriber_ProcessThe2MessageTheFirstTimeWith2DifferentRoutingKeys_MessagesMustBeRemovedFromTheRabbitMq() { //prepare IConfiguration configuration = ConfigurationHelper.ProvideConfiguration(); var exchangeName = "Subscriber_ProcessTheMessageTheFirstTime_MessageMustBeRemovedFromTheRabbitMq.exchangename"; configuration["rabbitmq:exchangename"] = exchangeName; configuration["rabbitmq:waitexchangename"] = exchangeName.Replace("exchangename", "waitexchangename"); var maxretrycount = 2; IContainer container = ConfigurationHelper.ConfigureContainer(configuration); //create Subscriber var bookingCreatedSubscriberFactory = container.Resolve <ISubscriberFactory>(); ISubscriber typedSubscriber = await bookingCreatedSubscriberFactory .CreateSubscriberAsync("Subscriber_ProcessTheMessageTheFirstTime_MessageMustBeRemovedFromTheRabbitMq" + ".typedbookingcreatedconsumer", new List <string> { "*.entity.create.booking", "*.entity.create.account" }, maxretrycount); BookingTypedConsumer bookingTypedConsumer = new BookingTypedConsumer(0); AccountTypedConsumer accountTypedConsumer = new AccountTypedConsumer(0); typedSubscriber.Subscribe(SubscriptionBuilder.Create() .AddSubscription("bookingcreated", () => bookingTypedConsumer) .AddSubscription("accountcreated", () => accountTypedConsumer).Build()); //create Publisher var publisher = container.Resolve <IPublisher>(); string bookingRoutingKey = "changetracker.entity.create.booking"; string accountRoutingKey = "changetracker.entity.create.account"; //act BookingCreated bookingCreated = new BookingCreated() { BookingName = string.Concat("Microsoft Sale", Guid.NewGuid().ToString()) }; AccountCreated accountCreated = new AccountCreated() { AccountLevel = 100 }; var bookingCreatedIntegrationEvent = new IntegrationEvent <BookingCreated>() { Content = bookingCreated, EventType = "bookingcreated" }; var accountCreatedIntegrationEvent = new IntegrationEvent <AccountCreated>() { Content = accountCreated, EventType = "accountcreated" }; await publisher.PublishEventAsync(bookingCreatedIntegrationEvent, bookingRoutingKey); await publisher.PublishEventAsync(accountCreatedIntegrationEvent, accountRoutingKey); await Task.Delay(200); //check bookingTypedConsumer.ProcessedIntegrationEvent.ShouldBeEquivalentTo(bookingCreatedIntegrationEvent); bookingTypedConsumer.CountOfAttempts.Should().Be(1); accountTypedConsumer.ProcessedIntegrationEvent.ShouldBeEquivalentTo(accountCreatedIntegrationEvent); accountTypedConsumer.CountOfAttempts.Should().Be(1); container.Dispose(); }
public async Task Subscriber_ExceededCountOfAttempts_MessageMustBeMovedToSpecificDeadLetterQueue() { //prepare IConfiguration configuration = ConfigurationHelper.ProvideConfiguration(); var exchangeName = "Subscriber_ExceededCountOfAttempts_MessageMustBeMovedToDeadLetterQueue.exchangename"; configuration["rabbitmq:exchangename"] = exchangeName; configuration["rabbitmq:waitexchangename"] = exchangeName.Replace("exchangename", "waitexchangename"); configuration["rabbitmq:retryfactor"] = 100.ToString(); var maxretrycount = 2; IContainer container = ConfigurationHelper.ConfigureContainer(configuration); //create Subscriber var bookingCreatedSubscriberFactory = container.Resolve <ISubscriberFactory>(); ISubscriber typedSubscriber = await bookingCreatedSubscriberFactory .CreateSubscriberAsync("Subscriber_ExceededCountOfAttempts_MessageMustBeMovedToDeadLetterQueue" + ".typedbookingcreatedconsumer", new List <string> { "*.entity.create.booking" }, maxretrycount); BookingTypedConsumer typedConsumer = new BookingTypedConsumer(3); IntegrationEvent <BookingCreated> actualDeadLetterCallbackIntegrationEvent = null; Exception actualDeadLetterCallbackException = null; typedSubscriber.Subscribe(SubscriptionBuilder.Create().AddDefaultSubscription(() => typedConsumer, (integrationEvent, exception) => { actualDeadLetterCallbackIntegrationEvent = integrationEvent; actualDeadLetterCallbackException = exception; return(Task.CompletedTask); }).Build()); //create Publisher var publisher = container.Resolve <IPublisher>(); string routingKey = "changetracker.entity.create.booking"; //act BookingCreated bookingCreated = new BookingCreated() { BookingName = string.Concat("Microsoft Sale", Guid.NewGuid().ToString()) }; var bookingCreatedIntegrationEvent = new IntegrationEvent <BookingCreated>() { Content = bookingCreated, EventType = "bookingcreated", CorrelationId = Guid.NewGuid() }; await publisher.PublishEventAsync(bookingCreatedIntegrationEvent, routingKey); //wait 1 second await Task.Delay(1000); //check var bus = container.Resolve <IAdvancedBus>(); var deadleterqueue = bus.QueueDeclare($"{exchangeName}.deadletter" + ".Subscriber_ExceededCountOfAttempts_MessageMustBeMovedToDeadLetterQueue." + "typedbookingcreatedconsumer"); IBasicGetResult result = bus.Get(deadleterqueue); var message = Encoding.UTF8.GetString(result.Body); var actualDeadLetterQueueIntergrationEvent = JsonConvert. DeserializeObject <IntegrationEvent <DeadLetterEventDescriptor <BookingCreated> > >(message); result.Info.RoutingKey.Should().Be("deadletter" + ".Subscriber_ExceededCountOfAttempts_MessageMustBeMovedToDeadLetterQueue" + ".typedbookingcreatedconsumer"); actualDeadLetterQueueIntergrationEvent.Content.Original .ShouldBeEquivalentTo(bookingCreatedIntegrationEvent); actualDeadLetterQueueIntergrationEvent.CorrelationId .ShouldBeEquivalentTo(bookingCreatedIntegrationEvent.CorrelationId); actualDeadLetterQueueIntergrationEvent.EventType.Should() .BeEquivalentTo(string.Concat("deadletter.", bookingCreatedIntegrationEvent.EventType)); actualDeadLetterCallbackException.Message.Should().Be("ExceptionHasBeenThrown"); actualDeadLetterCallbackException.Should().BeOfType <Exception>(); actualDeadLetterCallbackIntegrationEvent.ShouldBeEquivalentTo(bookingCreatedIntegrationEvent); typedConsumer.ProcessedIntegrationEvent.Should().BeNull(); typedConsumer.CountOfAttempts.Should().Be(3); container.Dispose(); }