public async Task Subscriber_2DifferentSubscribersWithEqualPrefetchCount_SubscribersShouldProcessEventsInParallelWithEqualSpeed()
        {
            //prepare
            IConfiguration configuration = ConfigurationHelper.ProvideConfiguration();
            var            exchangeName  =
                "Subscriber_2DifferentSubscribersWithEqualPrefetchCount_SubscribersShouldProcessEventsInParallelWithEqualSpeed.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 fastSubscriber =
                await bookingCreatedSubscriberFactory
                .CreateSubscriberAsync("Subscriber_2DifferentSubscribersWithEqualPrefetchCount_SubscribersShouldProcessEventsInParallelWithEqualSpeed" +
                                       ".first", new List <string>
            {
                "*.entity.create.booking",
            }, maxretrycount, 1);

            ISubscriber slowSubscriber =
                await bookingCreatedSubscriberFactory
                .CreateSubscriberAsync("Subscriber_2DifferentSubscribersWithEqualPrefetchCount_SubscribersShouldProcessEventsInParallelWithEqualSpeed" +
                                       ".second", new List <string>
            {
                "*.entity.create.booking",
            }, maxretrycount, 1);

            var firstBookingTypedSubscriberConsumer  = new BookingTypedParallellismCounterConsumer(3000);
            var secondBookingTypedSubscriberConsumer = new BookingTypedParallellismCounterConsumer(3000);

            fastSubscriber.Subscribe(SubscriptionBuilder.Create()
                                     .AddSubscription("bookingcreated", () => firstBookingTypedSubscriberConsumer)
                                     .Build());

            slowSubscriber.Subscribe(SubscriptionBuilder.Create()
                                     .AddSubscription("bookingcreated", () => secondBookingTypedSubscriberConsumer)
                                     .Build());

            //create Publisher

            var publisher = container.Resolve <IPublisher>();

            string bookingRoutingKey = "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"
            };

            for (int i = 1; i <= 8; i++)
            {
                await publisher.PublishEventAsync(bookingCreatedIntegrationEvent, bookingRoutingKey);
            }


            //wait 30 seconds
            await Task.Delay(30000);

            //check

            firstBookingTypedSubscriberConsumer.MaxParrelelEvents.Should().Be(1);
            firstBookingTypedSubscriberConsumer.CountOfProcessedEvents.Should().Be(8);

            secondBookingTypedSubscriberConsumer.MaxParrelelEvents.Should().Be(1);
            secondBookingTypedSubscriberConsumer.CountOfProcessedEvents.Should().Be(8);

            container.Dispose();
        }
Beispiel #2
0
        public async Task QueueInfoProvider_GetQueueInfo_CorrectCountOfReadyMessagesMustBeReturned()
        {
            //prepare
            IConfiguration configuration = ConfigurationHelper.ProvideConfiguration();
            var            exchangeName  =
                "QueueInfoProvider_GetQueueInfo_CorrectCountOfReadyMessagesMustBeReturned.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 fastSubscriber =
                await bookingCreatedSubscriberFactory
                .CreateSubscriberAsync("QueueInfoProvider_GetQueueInfo_CorrectCountOfReadyMessagesMustBeReturned" +
                                       ".fast", new List <string>
            {
                "*.entity.create.booking",
            }, maxretrycount, 5);

            ISubscriber slowSubscriber =
                await bookingCreatedSubscriberFactory
                .CreateSubscriberAsync("QueueInfoProvider_GetQueueInfo_CorrectCountOfReadyMessagesMustBeReturned" +
                                       ".slow", new List <string>
            {
                "*.entity.create.booking",
            }, maxretrycount, 1);


            //create Publisher

            var publisher = container.Resolve <IPublisher>();

            string bookingRoutingKey = "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"
            };

            for (int i = 1; i <= 8; i++)
            {
                await publisher.PublishEventAsync(bookingCreatedIntegrationEvent, bookingRoutingKey);
            }


            //wait 1 second
            await Task.Delay(1000);

            //ckeck the GetQueueInfo method first call
            var queueInfoProvider = container.Resolve <IQueueInfoProvider>();
            var fastSubscriberQueueSnapshotInfo = queueInfoProvider.GetQueueInfo(
                "QueueInfoProvider_GetQueueInfo_CorrectCountOfReadyMessagesMustBeReturned.fast");

            fastSubscriberQueueSnapshotInfo.CountOfMessages.Should().Be(8);

            var slowSubscriberQueueSnapshotInfo = queueInfoProvider.GetQueueInfo(
                "QueueInfoProvider_GetQueueInfo_CorrectCountOfReadyMessagesMustBeReturned.slow");

            slowSubscriberQueueSnapshotInfo.CountOfMessages.Should().Be(8);

            //Let's create Subscriber

            var fastBookingTypedSubscriberConsumer = new BookingTypedParallellismCounterConsumer(500);
            var slowBookingTypedSubscriberConsumer = new BookingTypedParallellismCounterConsumer(500);

            fastSubscriber.Subscribe(SubscriptionBuilder.Create()
                                     .AddSubscription("bookingcreated", () => fastBookingTypedSubscriberConsumer)
                                     .Build());

            slowSubscriber.Subscribe(SubscriptionBuilder.Create()
                                     .AddSubscription("bookingcreated", () => slowBookingTypedSubscriberConsumer)
                                     .Build());

            //wait 10 seconds
            await Task.Delay(10000);

            //check

            //ckeck the GetQueueInfo method second call
            fastSubscriberQueueSnapshotInfo = queueInfoProvider.GetQueueInfo(
                "QueueInfoProvider_GetQueueInfo_CorrectCountOfReadyMessagesMustBeReturned.fast");
            fastSubscriberQueueSnapshotInfo.CountOfMessages.Should().Be(0);

            slowSubscriberQueueSnapshotInfo = queueInfoProvider.GetQueueInfo(
                "QueueInfoProvider_GetQueueInfo_CorrectCountOfReadyMessagesMustBeReturned.slow");
            slowSubscriberQueueSnapshotInfo.CountOfMessages.Should().Be(0);

            container.Dispose();
        }