public void Test_Bad_Message_Rejected_On_Redelivery()
        {
            configuration.MessageHandlerErrorBehavior =
                MessageHandlerErrorBehavior.RejectOnRedelivery;

            using (var bus = new RabbitMQMessaging(configuration,
                                                   serviceProvider.GetService <ILoggerFactory>()))
            {
                bus.CreatePublisher().Publish(Encoding.UTF8.GetBytes(BadMessage.Text), "test-10");

                var handler = new MessageHandler {
                    OutputHelper = OutputHelper
                };
                var sub = bus.Subscribe(handler.Handle, "test-10");

                sub.Start();
                Thread.Sleep(500);
                sub.Stop();

                // 2 attempts to handle the message will be in the list
                Assert.Equal(2, handler.Messages.Count);
            }
        }
Beispiel #2
0
        public void TwoQueues_TwoRetries_IntegratedTest_Success()
        {
            var configuration = new RabbitMQConfiguration
            {
                Hosts = new List <string> {
                    "localhost"
                },
                User     = "******",
                Password = "******"
            };

            configuration.AddTopology <MultipleQueuesWithRetryTopologyFactory>(
                "test-funout", "test-funout-q1", "test-funout-q2", 4000, 8000);

            using (var bus = new RabbitMQMessaging(configuration, new LoggerFactory()))
            {
                bus.EnsureTopology("test-funout");

                bus.CreatePublisher().
                Publish(Encoding.UTF8.GetBytes("Simple Message"), "test-funout");

                var messages = new List <IMessageContext>();
                var sub      = bus.Subscribe((message, messageContext) =>
                {
                    messages.Add(messageContext);
                }, "test-funout-q1", "test-funout-q2");

                sub.Start();
                Thread.Sleep(500);
                sub.Stop();

                Assert.Equal(2, messages.Count);
                Assert.Contains(messages, x => x.Queue == "test-funout-q1");
                Assert.Contains(messages, x => x.Queue == "test-funout-q2");
            }
        }