use of javax.jms.QueueReceiver in project activemq-artemis by apache.
the class MessageConsumerTest method testGetQueueOnClosedConsumer.
@Test
public void testGetQueueOnClosedConsumer() throws Exception {
Connection consumerConnection = null;
try {
consumerConnection = createConnection();
Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
queueConsumer.close();
try {
((QueueReceiver) queueConsumer).getQueue();
Assert.fail("must throw a JMS IllegalStateException");
} catch (javax.jms.IllegalStateException e) {
// OK
}
} finally {
if (consumerConnection != null) {
consumerConnection.close();
}
}
}
use of javax.jms.QueueReceiver in project activemq-artemis by apache.
the class MessageConsumerTest method testGetQueue.
@Test
public void testGetQueue() throws Exception {
Connection consumerConnection = null;
try {
consumerConnection = createConnection();
Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer queueConsumer = consumerSession.createConsumer(queue1);
Queue q = ((QueueReceiver) queueConsumer).getQueue();
ProxyAssertSupport.assertEquals(queue1, q);
} finally {
if (consumerConnection != null) {
consumerConnection.close();
}
}
}
use of javax.jms.QueueReceiver in project wildfly by wildfly.
the class MessageDrivenTimeoutTestCase method receiveMessage.
static String receiveMessage(Queue replyQueue, InitialContext initCtx, boolean isCommitExpected) throws Exception {
QueueConnection connection = getConnection(initCtx);
connection.start();
try {
final QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
final QueueReceiver receiver = session.createReceiver(replyQueue);
// when expecting commit (message should be in queue): wait a bit longer before failing
// when expecting rollback (message should not be in queue): fail faster only till timeout elapses
final Message reply = receiver.receive(TimeoutUtil.adjust(isCommitExpected ? 5000 : TxTestUtil.timeoutWaitTime_ms));
// waiting for synchro could be finished before checking
Thread.sleep(TimeoutUtil.adjust(500));
if (reply == null)
return null;
return ((TextMessage) reply).getText();
} finally {
connection.close();
}
}
use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class MixedConsumerCheckIT method testAsyncThenSyncReceive.
/**
* Listener with a Consumer. Uses message listener (asynchronous receive).
* Try to receive() from different queue on same session.
* @throws javax.jms.IllegalStateException if test succeeds.
*/
@Test
public void testAsyncThenSyncReceive() throws Exception {
assertThrows(javax.jms.IllegalStateException.class, () -> {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
Queue queueTwo = queueSession.createQueue(QUEUE_NAME_TWO);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
QueueReceiver queueReceiverTwo = queueSession.createReceiver(queueTwo);
TestMessageListener listener = new TestMessageListener();
queueReceiver.setMessageListener(listener);
// should throw an exception
queueReceiverTwo.receiveNoWait();
});
}
use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class SSLSimpleQueueMessageIT method messageTestBase.
private void messageTestBase(MessageTestType mtt) throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
drainQueue(queueSession, queue);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
queueSender.send(mtt.gen(queueSession, (Serializable) queue));
} finally {
reconnect();
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
Aggregations