use of com.rabbitmq.jms.admin.RMQDestination in project rabbitmq-jms-client by rabbitmq.
the class TtlIT method publishAmqpConsumeJms.
private Message publishAmqpConsumeJms(boolean expiration) throws Exception {
Channel channel = connection.createChannel();
channel.queueDeclare(AMQP_QUEUE_NAME, // durable
false, // non-exclusive
false, // autoDelete
true, // options
null);
Map<String, Object> hdrs = new HashMap<>();
//
hdrs.put("JMSType", "TextMessage");
AMQP.BasicProperties.Builder propsBuilder = new AMQP.BasicProperties.Builder();
propsBuilder.headers(hdrs);
if (expiration) {
propsBuilder.expiration("10000");
}
String content = UUID.randomUUID().toString();
channel.basicPublish("", AMQP_QUEUE_NAME, propsBuilder.build(), content.getBytes());
queueConn.start();
QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Queue queue = new RMQDestination(AMQP_QUEUE_NAME, null, null, AMQP_QUEUE_NAME);
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
TextMessage message = (TextMessage) queueReceiver.receive(TEST_RECEIVE_TIMEOUT);
assertNotNull(message, "No message received");
assertEquals(content, message.getText(), "Payload doesn't match");
return message;
}
use of com.rabbitmq.jms.admin.RMQDestination in project rabbitmq-jms-client by rabbitmq.
the class RpcWithAmqpDirectReplyIT method doRpc.
Message doRpc(String messageContent) throws Exception {
Session session = clientConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TextMessage message = session.createTextMessage(messageContent);
message.setJMSCorrelationID(messageContent);
RMQDestination replyQueue = new RMQDestination("amq.rabbitmq.reply-to", "", "amq.rabbitmq.reply-to", "amq.rabbitmq.reply-to");
replyQueue.setDeclared(true);
MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));
MessageConsumer responseConsumer = session.createConsumer(replyQueue);
BlockingQueue<Message> queue = new ArrayBlockingQueue<>(1);
responseConsumer.setMessageListener(msg -> queue.add(msg));
message.setJMSReplyTo(replyQueue);
producer.send(message);
Message response = queue.poll(2, TimeUnit.SECONDS);
responseConsumer.close();
return response;
}
use of com.rabbitmq.jms.admin.RMQDestination in project rabbitmq-jms-client by rabbitmq.
the class RmqDestinationIT method createRmqDestinationWithArguments.
@Test
void createRmqDestinationWithArguments() throws Exception {
this.queueConn.start();
QueueSession session = this.queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = new RMQDestination(QUEUE_NAME, true, false, Collections.singletonMap("x-queue-type", "quorum"));
QueueSender sender = session.createSender(queue);
drainQueue(session, queue);
String body = String.valueOf(System.currentTimeMillis());
TextMessage msg = session.createTextMessage(body);
sender.send(msg);
CountDownLatch consumerLatch = new CountDownLatch(1);
AtomicReference<TextMessage> message = new AtomicReference<>();
MessageConsumer consumer = session.createConsumer(queue);
consumer.setMessageListener(m -> {
message.set((TextMessage) m);
consumerLatch.countDown();
});
assertThat(consumerLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(message.get().getText()).isEqualTo(body);
}
use of com.rabbitmq.jms.admin.RMQDestination 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 com.rabbitmq.jms.admin.RMQDestination in project rabbitmq-jms-client by rabbitmq.
the class SimpleAmqpQueueMessageIT method testSendToAmqpAndReceiveBytesMessage.
@Test
public void testSendToAmqpAndReceiveBytesMessage() 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);
BytesMessage message = queueSession.createBytesMessage();
message.setStringProperty(USER_STRING_PROPERTY_NAME, STRING_PROP_VALUE);
message.writeBytes(BYTE_ARRAY);
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<String>(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");
}
assertArrayEquals(BYTE_ARRAY, body, "Message received not identical to message sent");
}
Aggregations