Ejemplo n.º 1
0
        public void TestNoLocalConsumerConfiguration()
        {
            var connectionFactory = new Mock <IConnectionFactory>();
            var connection        = new Mock <IConnection>();
            var channel           = new Mock <R.IModel>();

            connectionFactory.Setup((f) => f.CreateConnection()).Returns(connection.Object);
            connection.Setup(c => c.CreateChannel(It.IsAny <bool>())).Returns(channel.Object);
            connection.Setup(c => c.IsOpen).Returns(true);
            channel.Setup(c => c.IsOpen).Returns(true);

            var queue   = "testQ";
            var noLocal = true;
            var blockingQueueConsumer = new BlockingQueueConsumer(
                connectionFactory.Object,
                new DefaultMessageHeadersConverter(),
                new ActiveObjectCounter <BlockingQueueConsumer>(),
                AcknowledgeMode.AUTO,
                true,
                1,
                true,
                null,
                noLocal,
                false,
                null,
                queue);

            blockingQueueConsumer.Start();
            channel.Verify(c => c.BasicConsume("testQ", AcknowledgeMode.AUTO.IsAutoAck(), string.Empty, noLocal, false, It.IsAny <IDictionary <string, object> >(), It.IsAny <R.IBasicConsumer>()));
            blockingQueueConsumer.Stop();
        }
Ejemplo n.º 2
0
        public void TestPrefetchIsSetOnFailedPassiveDeclaration()
        {
            var connectionFactory = new Mock <IConnectionFactory>();
            var connection        = new Mock <IConnection>();
            var channel           = new Mock <R.IModel>();

            connectionFactory.Setup((f) => f.CreateConnection()).Returns(connection.Object);
            connection.Setup(c => c.CreateChannel(It.IsAny <bool>())).Returns(channel.Object);
            connection.Setup(c => c.IsOpen).Returns(true);
            channel.Setup(c => c.IsOpen).Returns(true);
            var throws = new AtomicBoolean(false);

            channel.Setup(c => c.QueueDeclarePassive(It.IsAny <string>()))
            .Callback <string>((arg) =>
            {
                if (arg != "good")
                {
                    throws.Value = true;
                }
                else
                {
                    throws.Value = false;
                }
            })
            .Returns(() =>
            {
                if (throws.Value)
                {
                    throw new R.Exceptions.OperationInterruptedException(new R.ShutdownEventArgs(R.ShutdownInitiator.Peer, 0, "Expected"));
                }

                return(new R.QueueDeclareOk("any", 0, 0));
            });
            channel.Setup(c => c.BasicConsume(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IDictionary <string, object> >(), It.IsAny <R.IBasicConsumer>()))
            .Returns("consumerTag");
            var blockingQueueConsumer = new BlockingQueueConsumer(
                connectionFactory.Object,
                new DefaultMessageHeadersConverter(),
                new ActiveObjectCounter <BlockingQueueConsumer>(),
                AcknowledgeMode.AUTO,
                true,
                20,
                null,
                "good",
                "bad")
            {
                DeclarationRetries             = 1,
                RetryDeclarationInterval       = 10,
                FailedDeclarationRetryInterval = 10
            };

            blockingQueueConsumer.Start();
            channel.Verify(c => c.BasicQos(It.IsAny <uint>(), 20, It.IsAny <bool>()));
            blockingQueueConsumer.Stop();
        }
Ejemplo n.º 3
0
        public void TestTransactionalLowLevel()
        {
            var connectionFactory = new CachingConnectionFactory("localhost");
            var admin             = new RabbitAdmin(connectionFactory);

            admin.DeclareQueue(new Queue(QUEUE1_NAME));
            admin.DeclareQueue(new Queue(QUEUE2_NAME));
            var template = new RabbitTemplate(connectionFactory);
            var blockingQueueConsumer = new BlockingQueueConsumer(
                connectionFactory,
                new DefaultMessageHeadersConverter(),
                new ActiveObjectCounter <BlockingQueueConsumer>(),
                AcknowledgeMode.AUTO,
                true,
                1,
                null,
                QUEUE1_NAME,
                QUEUE2_NAME);
            var prefix = Guid.NewGuid().ToString();

            blockingQueueConsumer.TagStrategy = new TagStrategy(prefix);
            var latch = new CountdownEvent(2);

            try
            {
                blockingQueueConsumer.Start();
                var consumers = blockingQueueConsumer.CurrentConsumers();
                Assert.Equal(2, consumers.Count);
                var tags = new List <string>()
                {
                    consumers[0].ConsumerTag, consumers[1].ConsumerTag
                };
                Assert.Contains(prefix + "#" + QUEUE1_NAME, tags);
                Assert.Contains(prefix + "#" + QUEUE2_NAME, tags);
                blockingQueueConsumer.Stop();
                Assert.Null(template.ReceiveAndConvert <object>(QUEUE1_NAME));
            }
            finally
            {
                admin.DeleteQueue(QUEUE1_NAME);
                admin.DeleteQueue(QUEUE2_NAME);
                connectionFactory.Destroy();
            }
        }