use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class SimpleAmqpQueueMessageIT method testSendFromJmsAndReceiveJmsTextMessage.
@Test
public void testSendFromJmsAndReceiveJmsTextMessage() throws Exception {
String queueName = UUID.randomUUID().toString();
channel.queueDeclare(queueName, // durable
false, // non-exclusive
false, // autoDelete
true, // options
null);
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
// write-only AMQP-mapped queue
Queue queue = new RMQDestination(queueName, "", queueName, null);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = queueSession.createTextMessage(MESSAGE);
message.setStringProperty("JMSType", "TextMessage");
message.setStringProperty(USER_STRING_PROPERTY_NAME, STRING_PROP_VALUE);
queueSender.send(message);
queueSession.close();
queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
// read-only AMQP-mapped queue
queue = new RMQDestination(queueName, null, null, queueName);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
message = (TextMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
channel.queueDelete(queueName);
assertNotNull(message, "No message received");
assertEquals(MESSAGE, message.getText(), "Payload doesn't match");
assertEquals(STRING_PROP_VALUE, message.getStringProperty(USER_STRING_PROPERTY_NAME), "String property not transferred");
assertThat(message.getJMSTimestamp()).isGreaterThan(0);
}
use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class SimpleAmqpQueueMessageIT method testSendFromAmqpAndReceiveBytesMessage.
@Test
public void testSendFromAmqpAndReceiveBytesMessage() 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);
hdrs.put("JMSType", USER_JMS_TYPE_SETTING);
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, BYTE_ARRAY);
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
// read-only AMQP-mapped queue
Queue queue = new RMQDestination(QUEUE_NAME_NON_EXCLUSIVE, null, null, QUEUE_NAME_NON_EXCLUSIVE);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
BytesMessage message = (BytesMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
assertNotNull(message, "No message received");
byte[] bytes = new byte[BYTE_ARRAY.length + 2];
int bytesIn = message.readBytes(bytes);
assertEquals(BYTE_ARRAY.length, bytesIn, "Message payload not correct size");
byte[] bytesTrunc = new byte[bytesIn];
System.arraycopy(bytes, 0, bytesTrunc, 0, bytesIn);
assertArrayEquals(BYTE_ARRAY, bytesTrunc, "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(USER_JMS_TYPE_SETTING, 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");
assertThat(message.getJMSTimestamp()).isZero();
}
use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class TemporaryQueueIT method testQueueSendAndReceiveTwoSessions.
@Test
public void testQueueSendAndReceiveTwoSessions() throws Exception {
queueConn.start();
QueueSession queueSession1 = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
QueueSession queueSession2 = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession1.createTemporaryQueue();
QueueSender queueSender = queueSession1.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = queueSession1.createTextMessage(MESSAGE);
queueSender.send(message);
QueueReceiver queueReceiver = queueSession2.createReceiver(queue);
message = (TextMessage) queueReceiver.receive(1000);
assertNotNull(message);
assertEquals(MESSAGE, message.getText());
}
use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class TemporaryQueueIT method testQueueSendAndReceiveSingleSession.
@Test
public void testQueueSendAndReceiveSingleSession() throws Exception {
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = queueSession.createTemporaryQueue();
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = queueSession.createTextMessage(MESSAGE);
queueSender.send(message);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
message = (TextMessage) queueReceiver.receive(1000);
assertNotNull(message);
assertEquals(MESSAGE, message.getText());
}
use of javax.jms.QueueReceiver in project rabbitmq-jms-client by rabbitmq.
the class SimpleQueueMessageDefaultsIT 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.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);
Message m = queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
mtt.check(m, (Serializable) queue);
mtt.checkAttrs(m, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY);
}
Aggregations