use of javax.jms.QueueConnection in project rabbitmq-jms-client by rabbitmq.
the class RequeueMessageOnTimeoutIT method requeueParameterFalseTimeoutConsumerIsClosed.
@Test
void requeueParameterFalseTimeoutConsumerIsClosed() throws Exception {
sendMessage();
QueueConnection connection = null;
try {
connection = connection(true, false);
QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
List<Message> receivedMessages = Collections.synchronizedList(new ArrayList<>());
AtomicBoolean interrupted = new AtomicBoolean(false);
queueReceiver.setMessageListener(message -> {
receivedMessages.add(message);
if (receivedMessages.size() == 1) {
try {
Thread.sleep(REQUEUE_TIMEOUT_MS * 2);
} catch (InterruptedException e) {
interrupted.set(true);
}
}
});
TestUtils.waitUntil(Duration.ofSeconds(5), () -> receivedMessages.size() == 1);
assertThat(receivedMessages).hasSize(1);
assertThat(receivedMessages.get(0).getJMSRedelivered()).isFalse();
// another consumer can consume the message
queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
Message message = queueReceiver.receive(1000L);
assertNotNull(message);
assertTrue(message.getJMSRedelivered());
assertThat(interrupted.get()).isTrue();
} finally {
if (connection != null) {
connection.close();
}
}
}
use of javax.jms.QueueConnection in project rabbitmq-jms-client by rabbitmq.
the class RequeueMessageOnTimeoutIT method connection.
private QueueConnection connection(boolean requeueOnException, boolean requeueOnTimeout) throws Exception {
RMQConnectionFactory connectionFactory = (RMQConnectionFactory) AbstractTestConnectionFactory.getTestConnectionFactory().getConnectionFactory();
connectionFactory.setRequeueOnMessageListenerException(requeueOnException);
connectionFactory.setRequeueOnTimeout(requeueOnTimeout);
connectionFactory.setOnMessageTimeoutMs(REQUEUE_TIMEOUT_MS);
QueueConnection queueConnection = connectionFactory.createQueueConnection();
queueConnection.start();
return queueConnection;
}
Aggregations