use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class SimpleAmqpQueueMessageIT method testSendToAmqpAndReceiveTextMessage.
@Test
public void testSendToAmqpAndReceiveTextMessage() throws Exception {
channel.queueDeclare(QUEUE_NAME, // durable
false, // exclusive
true, // autoDelete
true, // options
null);
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
// write-only AMQP-mapped queue
Queue queue = new RMQDestination(QUEUE_NAME, "", QUEUE_NAME, null);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
queueSender.setPriority(9);
TextMessage message = queueSession.createTextMessage(MESSAGE);
message.setStringProperty(USER_STRING_PROPERTY_NAME, STRING_PROP_VALUE);
queueSender.send(message);
queueConn.close();
GetResponse response = channel.basicGet(QUEUE_NAME, false);
assertNotNull(response, "basicGet failed to retrieve a response");
byte[] body = response.getBody();
assertNotNull(body, "body of response is null");
{
Map<String, Object> hdrs = response.getProps().getHeaders();
assertEquals(new HashSet<>(Arrays.asList("JMSMessageID", "JMSDeliveryMode", "JMSPriority", "JMSTimestamp", USER_STRING_PROPERTY_NAME)), hdrs.keySet(), "Some keys missing");
assertEquals(9, hdrs.get("JMSPriority"), "Priority wrong");
// toString is a bit wiffy
assertEquals("NON_PERSISTENT", hdrs.get("JMSDeliveryMode").toString(), "Delivery mode wrong");
assertEquals(STRING_PROP_VALUE, hdrs.get(USER_STRING_PROPERTY_NAME).toString(), "String property wrong");
}
assertEquals(MESSAGE, new String(body, "UTF-8"), "Message received not identical to message sent");
}
use of javax.jms.QueueSender 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.QueueSender 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.QueueSender 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);
}
use of javax.jms.QueueSender in project rabbitmq-jms-client by rabbitmq.
the class SimpleSendReceiveTransactionIT method testQueueSendAndRollback.
@Test
public void testQueueSendAndRollback() 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.rollback();
} 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.receiveNoWait();
assertNull(message);
}
Aggregations