use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class SimpleSendReceiveTransactionIT method testSendAndCommitAndReceiveMessage.
@Test
public void testSendAndCommitAndReceiveMessage() throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(true, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = queueSession.createTextMessage(MESSAGE);
queueSender.send(message);
queueSession.commit();
} finally {
reconnect();
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
TextMessage message = (TextMessage) queueReceiver.receive();
assertEquals(MESSAGE, message.getText());
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class MetricsCollectionIT method sendAndConsumeMessage.
protected void sendAndConsumeMessage() throws Exception {
MessageTestType mtt = MessageTestType.TEXT;
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);
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class MultipleBrowseQueueMessageIT method messageTestBase.
private void messageTestBase(MessageTestType mtt, String selector, int numExpected) 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);
{
// Browse queue before receiving message
QueueBrowser queueBrowser = queueSession.createBrowser(queue, selector);
for (int repeat = 0; repeat < REPEATS; ++repeat) {
Enumeration<?> e = queueBrowser.getEnumeration();
int numE = 0;
Message msg = null;
while (e.hasMoreElements()) {
++numE;
msg = (Message) e.nextElement();
mtt.check(msg, (Serializable) queue);
}
assertEquals(numExpected, numE, "Wrong number of messages on browse queue");
}
}
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
mtt.check(queueReceiver.receive(TEST_RECEIVE_TIMEOUT), (Serializable) queue);
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class ObjectMessageSerializationIT method testReceiveObjectMessageWithPayload.
protected void testReceiveObjectMessageWithPayload(Object payload) 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.send(MessageTestType.OBJECT.gen(queueSession, (Serializable) payload));
} finally {
reconnect(Arrays.asList("java.lang", "com.rabbitmq.jms"));
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
RMQObjectMessage m = (RMQObjectMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
assertEquals(m.getObject(), payload);
assertEquals(m.getObject(TRUSTED_PACKAGES), payload);
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class AsyncConsumerOnMessageHangIT method testSendAndAsyncReceiveTextMessageWithHang.
/**
* Basic send and receive with a Consumer. Uses serial send followed by async receive.
* @throws Exception if test error.
*/
@Test
public void testSendAndAsyncReceiveTextMessageWithHang() throws Exception {
try {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = queueSession.createTextMessage(MESSAGE);
queueSender.send(message);
} finally {
reconnect();
}
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createQueue(QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
MessageListener listener = new MessageListener();
queueReceiver.setMessageListener(listener);
Thread.sleep(4000);
TextMessage message = (TextMessage) listener.getLastMessage();
assertEquals(MESSAGE, message.getText());
assertEquals(1, listener.getMessageCount());
assertTrue(listener.isSuccess());
assertTrue(listener.isInterrupted());
}
Aggregations