use of javax.jms.QueueConnection in project rabbitmq-jms-client by rabbitmq.
the class RequeueMessageOnTimeoutIT method requeueParameterTrueTimeoutMessageShouldBeNackedAndConsumerStillActive.
@Test
void requeueParameterTrueTimeoutMessageShouldBeNackedAndConsumerStillActive() throws Exception {
sendMessage();
QueueConnection connection = null;
try {
connection = connection(true, true);
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() == 2);
assertThat(interrupted.get()).isTrue();
assertThat(receivedMessages).hasSize(2);
assertThat(receivedMessages.get(0).getJMSRedelivered()).isFalse();
assertThat(receivedMessages.get(1).getJMSRedelivered()).isTrue();
} finally {
if (connection != null) {
connection.close();
}
}
}
use of javax.jms.QueueConnection in project rabbitmq-jms-client by rabbitmq.
the class RequeueMessageOnTimeoutIT method requeueParameterTrueNoExceptionInListenerQueueShouldBeEmpty.
@Test
public void requeueParameterTrueNoExceptionInListenerQueueShouldBeEmpty() 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);
final CountDownLatch latch = new CountDownLatch(1);
queueReceiver.setMessageListener(message -> latch.countDown());
// the message has been consumed, no longer in the queue
queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
Message message = queueReceiver.receive(1000L);
assertNull(message);
} finally {
if (connection != null) {
connection.close();
}
}
}
use of javax.jms.QueueConnection in project iaf by ibissource.
the class MessagingSource method createSession.
public Session createSession(boolean transacted, int acknowledgeMode) throws IbisException {
Connection connection = null;
;
Session session;
try {
connection = getConnection();
} catch (JMSException e) {
throw new JmsException("could not obtain Connection", e);
}
try {
// if (log.isDebugEnabled()) log.debug(getLogPrefix()+"creating Session, openSessionCount before ["+openSessionCount.getValue()+"]");
if (useJms102()) {
if (connection instanceof QueueConnection) {
session = ((QueueConnection) connection).createQueueSession(transacted, acknowledgeMode);
} else {
session = ((TopicConnection) connection).createTopicSession(transacted, acknowledgeMode);
}
} else {
session = connection.createSession(transacted, acknowledgeMode);
}
openSessionCount.increase();
if (connectionsArePooled()) {
connectionTable.put(session, connection);
}
return session;
} catch (JMSException e) {
releaseConnection(connection);
throw new JmsException("could not create Session", e);
}
}
use of javax.jms.QueueConnection in project qpid-broker-j by apache.
the class QueueReceiverTest method createReceiver.
@Test
public void createReceiver() throws Exception {
Queue queue = createQueue(getTestName());
QueueConnection queueConnection = getQueueConnection();
try {
queueConnection.start();
Utils.sendMessages(queueConnection, queue, 3);
QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueReceiver receiver = session.createReceiver(queue, String.format("%s=2", INDEX));
assertEquals("Queue names should match from QueueReceiver", queue.getQueueName(), receiver.getQueue().getQueueName());
Message received = receiver.receive(getReceiveTimeout());
assertNotNull("Message is not received", received);
assertEquals("Unexpected message is received", 2, received.getIntProperty(INDEX));
} finally {
queueConnection.close();
}
}
use of javax.jms.QueueConnection in project qpid-broker-j by apache.
the class QueueSessionTest method testQueueSessionCannotCreateTemporaryTopics.
@Test
public void testQueueSessionCannotCreateTemporaryTopics() throws Exception {
QueueConnection queueConnection = getQueueConnection();
try {
QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
try {
queueSession.createTemporaryTopic();
fail("expected exception did not occur");
} catch (javax.jms.IllegalStateException s) {
// PASS
}
} finally {
queueConnection.close();
}
}
Aggregations