use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class SimpleAmqpQueueMessageIT method testSendFromAmqpAndReceiveTextMessage.
@Test
public void testSendFromAmqpAndReceiveTextMessage() throws Exception {
channel.queueDeclare(QUEUE_NAME_NON_EXCLUSIVE, // durable
false, // non-exclusive
false, // autoDelete
true, // options
null);
Map<String, Object> hdrs = new HashMap<String, Object>();
hdrs.put(USER_STRING_PROPERTY_NAME, STRING_PROP_VALUE);
// To signal a JMS TextMessage
hdrs.put("JMSType", "TextMessage");
hdrs.put("JMSPriority", 21);
hdrs.put("JMSDeliveryMode", 2);
hdrs.put("DummyProp", 42);
hdrs.put("rmq.jms.silly", "silly attempt");
AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().deliveryMode(1).priority(6).headers(hdrs).build();
channel.basicPublish("", QUEUE_NAME_NON_EXCLUSIVE, props, MESSAGE.getBytes("UTF-8"));
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
// read-only AMQP-mapped queue
Queue queue = (Queue) new RMQDestination(QUEUE_NAME_NON_EXCLUSIVE, null, null, QUEUE_NAME_NON_EXCLUSIVE);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
TextMessage message = (TextMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
assertNotNull(message, "No message received");
assertEquals(MESSAGE, message.getText(), "Payload doesn't match");
// override should work
assertEquals(21, message.getJMSPriority(), "Priority incorrect");
// override should fail
assertEquals(1, message.getJMSDeliveryMode(), "Delivery mode incorrect");
// override should work
assertEquals("TextMessage", message.getJMSType(), "JMSType not set correctly");
Enumeration<?> propNames = message.getPropertyNames();
Set<String> propNameSet = new HashSet<String>();
while (propNames.hasMoreElements()) {
propNameSet.add((String) propNames.nextElement());
}
assertEquals(new HashSet<>(Arrays.asList(USER_STRING_PROPERTY_NAME, "DummyProp")), propNameSet, "Headers not set correctly");
assertEquals(STRING_PROP_VALUE, message.getStringProperty(USER_STRING_PROPERTY_NAME), "String property not transferred");
assertEquals("42", message.getStringProperty("DummyProp"), "Numeric property not transferred");
}
use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class SimpleBrowseQueueMessageIT 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);
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.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class SimpleQueueMessageIT 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);
}
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 ReceiveNoWaitIT 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.receiveNoWait(), (Serializable) queue);
}
Aggregations