use of com.rabbitmq.jms.admin.RMQDestination in project rabbitmq-jms-client by rabbitmq.
the class RMQSession method createProducer.
/**
* {@inheritDoc}
* <p>
* <b>Note</b>: The destination may be null.
* </p>
*/
@Override
public MessageProducer createProducer(Destination destination) throws JMSException {
logger.trace("create producer for destination '{}' on session '{}'", destination, this);
illegalStateExceptionIfClosed();
RMQDestination dest = (RMQDestination) destination;
declareDestinationIfNecessary(dest);
RMQMessageProducer producer = new RMQMessageProducer(this, dest, this.preferProducerMessageProperty, this.amqpPropertiesCustomiser);
this.producers.add(producer);
return producer;
}
use of com.rabbitmq.jms.admin.RMQDestination 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 com.rabbitmq.jms.admin.RMQDestination 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 = (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 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 = (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");
}
use of com.rabbitmq.jms.admin.RMQDestination 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 = (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");
}
Aggregations