public void TestListenerSendsMessageAndThenContainerCommits() { var connectionFactory = this.CreateConnectionFactory(); var template = new RabbitTemplate(connectionFactory); new RabbitAdmin(connectionFactory).DeclareQueue(sendQueue); this.acknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.Auto; this.transactional = true; var latch = new CountdownEvent(1); this.container = this.CreateContainer(queue.Name, new ChannelSenderListener(sendQueue.Name, latch, false), connectionFactory); template.ConvertAndSend(queue.Name, "foo"); var timeout = this.GetTimeout(); Logger.Debug("Waiting for messages with timeout = " + timeout + " (s)"); var waited = latch.Wait(new TimeSpan(0, 0, timeout)); Assert.True(waited, "Timed out waiting for message"); Thread.Sleep(500); // All messages committed var bytes = (byte[])template.ReceiveAndConvert(sendQueue.Name); Assert.NotNull(bytes); Assert.AreEqual("bar", Encoding.UTF8.GetString(bytes)); Assert.AreEqual(null, template.ReceiveAndConvert(queue.Name)); }
public void TestListenerSendsMessageAndThenRollback() { var connectionFactory = this.CreateConnectionFactory(); var template = new RabbitTemplate(connectionFactory); new RabbitAdmin(connectionFactory).DeclareQueue(sendQueue); this.acknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.Auto; this.transactional = true; var latch = new CountdownEvent(1); this.container = this.CreateContainer(queue.Name, new ChannelSenderListener(sendQueue.Name, latch, true), connectionFactory); template.ConvertAndSend(queue.Name, "foo"); var timeout = this.GetTimeout(); Logger.Debug("Waiting for messages with timeout = " + timeout + " (s)"); var waited = latch.Wait(timeout * 1000); Assert.True(waited, "Timed out waiting for message"); this.container.Stop(); Thread.Sleep(200); // Foo message is redelivered Assert.AreEqual("foo", template.ReceiveAndConvert(queue.Name)); // Sending of bar message is also rolled back Assert.Null(template.ReceiveAndConvert(sendQueue.Name)); }
/// <summary>Initializes a new instance of the <see cref="SimpleMessageListenerContainerIntegrationTests"/> class.</summary> /// <param name="messageCount">The message count.</param> /// <param name="concurrency">The concurrency.</param> /// <param name="acknowledgeMode">The acknowledge mode.</param> /// <param name="transactional">The transactional.</param> /// <param name="txSize">The tx size.</param> /// <param name="externalTransaction">The external transaction.</param> public SimpleMessageListenerContainerIntegrationTests(int messageCount, int concurrency, AcknowledgeModeUtils.AcknowledgeMode acknowledgeMode, bool transactional, int txSize, bool externalTransaction) { this.messageCount = messageCount; this.concurrentConsumers = concurrency; this.acknowledgeMode = acknowledgeMode; this.transactional = transactional; this.txSize = txSize; this.externalTransaction = externalTransaction; }
/// <summary>Initializes a new instance of the <see cref="BlockingQueueConsumer"/> class. Create a consumer. The consumer must not attempt to use the connection factory or communicate with the broker until it is started.</summary> /// <param name="connectionFactory">The connection factory.</param> /// <param name="messagePropertiesConverter">The message properties converter.</param> /// <param name="activeObjectCounter">The active object counter.</param> /// <param name="acknowledgeMode">The acknowledge mode.</param> /// <param name="transactional">if set to <c>true</c> [transactional].</param> /// <param name="prefetchCount">The prefetch count.</param> /// <param name="queues">The queues.</param> public BlockingQueueConsumer( IConnectionFactory connectionFactory, IMessagePropertiesConverter messagePropertiesConverter, ActiveObjectCounter <BlockingQueueConsumer> activeObjectCounter, AcknowledgeModeUtils.AcknowledgeMode acknowledgeMode, bool transactional, int prefetchCount, params string[] queues) : this(connectionFactory, messagePropertiesConverter, activeObjectCounter, acknowledgeMode, transactional, prefetchCount, true, queues) { }
public void SetUp() { this.concurrentConsumers = 1; this.messageCount = 10; this.transactional = false; this.acknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.Auto; this.brokerIsRunning = BrokerRunning.IsRunningWithEmptyQueues(queue, sendQueue); this.brokerIsRunning.Apply(); Assert.IsTrue(this.container == null); }
/// <summary>Initializes a new instance of the <see cref="BlockingQueueConsumer"/> class. Create a consumer. The consumer must not attempt to use the connection factory or communicate with the broker until it is started.</summary> /// <param name="connectionFactory">The connection factory.</param> /// <param name="messagePropertiesConverter">The message properties converter.</param> /// <param name="activeObjectCounter">The active object counter.</param> /// <param name="acknowledgeMode">The acknowledge mode.</param> /// <param name="transactional">if set to <c>true</c> [transactional].</param> /// <param name="prefetchCount">The prefetch count.</param> /// <param name="defaultRequeueRejected">The default requeue rejected.</param> /// <param name="queues">The queues.</param> public BlockingQueueConsumer( IConnectionFactory connectionFactory, IMessagePropertiesConverter messagePropertiesConverter, ActiveObjectCounter <BlockingQueueConsumer> activeObjectCounter, AcknowledgeModeUtils.AcknowledgeMode acknowledgeMode, bool transactional, int prefetchCount, bool defaultRequeueRejected, params string[] queues) { this.connectionFactory = connectionFactory; this.messagePropertiesConverter = messagePropertiesConverter; this.activeObjectCounter = activeObjectCounter; this.acknowledgeMode = acknowledgeMode; this.transactional = transactional; this.prefetchCount = prefetchCount; this.defaultRequeueRejected = defaultRequeueRejected; this.queues = queues; }
public void TestListenerRecoversFromBogusDoubleAck() { var template = new RabbitTemplate(this.CreateConnectionFactory()); this.acknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.Manual; var latch = new CountdownEvent(this.messageCount); this.container = this.CreateContainer(queue.Name, new ManualAckListener(latch), this.CreateConnectionFactory()); for (var i = 0; i < this.messageCount; i++) { template.ConvertAndSend(queue.Name, i + "foo"); } var timeout = this.GetTimeout(); Logger.Debug("Waiting for messages with timeout = " + timeout + " (s)"); var waited = latch.Wait(new TimeSpan(0, 0, timeout)); Assert.True(waited, "Timed out waiting for message"); Assert.Null(template.ReceiveAndConvert(queue.Name)); }
/// <summary> /// Initializes a new instance of the <see cref="BlockingQueueConsumer"/> class. Create a consumer. The consumer must not attempt to use the connection factory or communicate with the broker until it is started. /// </summary> /// <param name="connectionFactory"> /// The connection factory. /// </param> /// <param name="activeObjectCounter"> /// The active object counter. /// </param> /// <param name="acknowledgeMode"> /// The acknowledge mode. /// </param> /// <param name="transactional"> /// The transactional. /// </param> /// <param name="prefetchCount"> /// The prefetch count. /// </param> /// <param name="queues"> /// The queues. /// </param> public BlockingQueueConsumer(IConnectionFactory connectionFactory, ActiveObjectCounter<BlockingQueueConsumer> activeObjectCounter, AcknowledgeModeUtils.AcknowledgeMode acknowledgeMode, bool transactional, int prefetchCount, int prefetchSize, params string[] queues) { this.connectionFactory = connectionFactory; this.activeObjectCounter = activeObjectCounter; this.acknowledgeMode = acknowledgeMode; this.transactional = transactional; this.prefetchCount = prefetchCount; this.prefetchSize = prefetchSize; this.queues = queues; }
public void TestListenerRecoversAndTemplateSharesConnectionFactory() { var connectionFactory = this.CreateConnectionFactory(); var template = new RabbitTemplate(connectionFactory); this.acknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.Manual; var latch = new CountdownEvent(this.messageCount); this.container = this.CreateContainer(queue.Name, new ManualAckListener(latch), connectionFactory); for (var i = 0; i < this.messageCount; i++) { template.ConvertAndSend(queue.Name, i + "foo"); } var timeout = this.GetTimeout(); Logger.Debug("Waiting for messages with timeout = " + timeout + " (s)"); var waited = latch.Wait(new TimeSpan(0, 0, timeout)); Assert.True(waited, "Timed out waiting for message"); Assert.Null(template.ReceiveAndConvert(queue.Name)); }
private static object[] GetParams(int i, int messageCount, int concurrency, AcknowledgeModeUtils.AcknowledgeMode acknowledgeMode, bool transactional, int txSize) { // "i" is just a counter to make it easier to identify the test in the log return(new object[] { messageCount, concurrency, acknowledgeMode, transactional, txSize, false }); }
private static object[] GetParams(int i, int messageCount, int concurrency, AcknowledgeModeUtils.AcknowledgeMode acknowledgeMode, int txSize) { // For this test always us a transaction if it makes sense... return(GetParams(i, messageCount, concurrency, acknowledgeMode, acknowledgeMode.TransactionAllowed(), txSize)); }
public void TestListenerRecoversFromBogusDoubleAck() { var template = new RabbitTemplate(CreateConnectionFactory()); acknowledgeMode = AcknowledgeModeUtils.AcknowledgeMode.MANUAL; var latch = new CountdownEvent(messageCount); container = CreateContainer(queue.Name, new ManualAckListener(latch), CreateConnectionFactory()); for (var i = 0; i < messageCount; i++) { template.ConvertAndSend(queue.Name, i + "foo"); } var timeout = GetTimeout(); logger.Debug("Waiting for messages with timeout = " + timeout + " (s)"); var waited = latch.Wait(timeout * 1000); Assert.True(waited, "Timed out waiting for message"); Assert.Null(template.ReceiveAndConvert(queue.Name)); }
/// <summary>Initializes a new instance of the <see cref="BlockingQueueConsumer"/> class. Create a consumer. The consumer must not attempt to use the connection factory or communicate with the broker until it is started.</summary> /// <param name="connectionFactory">The connection factory.</param> /// <param name="messagePropertiesConverter">The message properties converter.</param> /// <param name="activeObjectCounter">The active object counter.</param> /// <param name="acknowledgeMode">The acknowledge mode.</param> /// <param name="transactional">if set to <c>true</c> [transactional].</param> /// <param name="prefetchCount">The prefetch count.</param> /// <param name="defaultRequeueRejected">The default requeue rejected.</param> /// <param name="queues">The queues.</param> public BlockingQueueConsumer( IConnectionFactory connectionFactory, IMessagePropertiesConverter messagePropertiesConverter, ActiveObjectCounter<BlockingQueueConsumer> activeObjectCounter, AcknowledgeModeUtils.AcknowledgeMode acknowledgeMode, bool transactional, int prefetchCount, bool defaultRequeueRejected, params string[] queues) { this.connectionFactory = connectionFactory; this.messagePropertiesConverter = messagePropertiesConverter; this.activeObjectCounter = activeObjectCounter; this.acknowledgeMode = acknowledgeMode; this.transactional = transactional; this.prefetchCount = prefetchCount; this.defaultRequeueRejected = defaultRequeueRejected; this.queues = queues; }
private static object[] GetParams(int i, int messageCount, int concurrency, AcknowledgeModeUtils.AcknowledgeMode acknowledgeMode) { return(GetParams(i, messageCount, concurrency, acknowledgeMode, 1)); }