public void Queue_Processing_CorruptedEvent()
        {
            // Enqueue events for further handling
            bus.Subscribe(testService.Enque <TestEvent>());

            // except test to throw Exception event
            Exception exception = null;

            bus.Subscribe <Exception>(e =>
                                      exception = e);

            int counter          = 0;
            int backofIntervalMs = 50;
            // Subscribe handler which waits 50 ms
            Delegate <TestEvent> handler = (e) => { counter++; throw new NotImplementedException(); };

            bus.Subscribe(handler.WhenQueued().RetryQueued(3,
                                                           Backoff.Fixed(TimeSpan.FromMilliseconds(backofIntervalMs))
                                                           ));

            bus.Publish(new TestEvent(), this);

            // There is event to handle
            Assert.AreEqual(1, repository.Queue.Where(e => e.DeclaringEventType == typeof(TestEvent).AssemblyQualifiedName).Count());

            testService.ProcessEvents();

            Assert.AreEqual(0, repository.Queue.Where(e => e.DeclaringEventType == typeof(TestEvent).ToString()).Count());
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(FormatException));
        }
Exemple #2
0
 protected virtual void SubscribeForRequeueStuckEvents(EventBusService eventBus)
 {
     eventBus.Subscribe(Enque <RequeueStuckEvents>(TimeSpan.FromSeconds(40)));
     eventBus.Subscribe(this.WhenQueued());
     // enqueue a first event
     eventBus.Publish(new RequeueStuckEvents(), this);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="app"></param>
        public static void RabbitMQAutoSubscribe(this IApplicationBuilder app, Container container)
        {
            EventBusService eventBus = container.GetRequiredService <EventBusService>();

            foreach (Type mType in typeof(IEvent).GetAssemblies())
            {
                foreach (Type hType in typeof(IEventHandler <>).GetMakeGenericType(mType))
                {
                    eventBus.Subscribe(mType, hType);
                }
            }
        }
        public void Queue_ProcessingTimelimit()
        {
            // Enqueue events for further handling
            bus.Subscribe(testService.Enque <TestEvent>());

            // Subscribe handler which waits 50 ms
            bus.Subscribe <QueuedEvent <TestEvent> >((e) => Task.Delay(50).Wait());

            for (int i = 0; i < 10; i++)
            {
                bus.Publish(new TestEvent(), this);
            }

            // expect to handle no more than 5 events
            testService.ProcessingTimeLimit = TimeSpan.FromMilliseconds(249);
            var result = testService.ProcessEvents();

            Console.Write($"Number of items processed: {result.Processed}");
            Assert.IsTrue(4 == result.Processed || 5 == result.Processed);
        }