public void TestNoLocalConsumerConfiguration() { var connectionFactory = new Mock <IConnectionFactory>(); var connection = new Mock <IConnection>(); var channel = new Mock <RC.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 <RC.IBasicConsumer>())); blockingQueueConsumer.Stop(); }
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); try { blockingQueueConsumer.Start(); int n = 0; var consumers = blockingQueueConsumer.CurrentConsumers(); // Wait for consumers while (n < 100) { if (consumers.Count < 2) { n++; Thread.Sleep(100); consumers = blockingQueueConsumer.CurrentConsumers(); } else { break; } } 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(); } }
public void TestPrefetchIsSetOnFailedPassiveDeclaration() { var connectionFactory = new Mock <IConnectionFactory>(); var connection = new Mock <IConnection>(); var channel = new Mock <RC.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 RC.Exceptions.OperationInterruptedException(new RC.ShutdownEventArgs(RC.ShutdownInitiator.Peer, 0, "Expected")); } return(new RC.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 <RC.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(); }