use of com.rabbitmq.jms.client.message.RMQTextMessage in project rabbitmq-jms-client by rabbitmq.
the class RMQMessageProducer method sendAMQPMessage.
private void sendAMQPMessage(RMQDestination destination, RMQMessage msg, int deliveryMode, int priority, long timeToLive) throws JMSException {
if (!destination.amqpWritable()) {
this.logger.error("Cannot write to AMQP destination {}", destination);
throw new RMQJMSException("Cannot write to AMQP destination", new UnsupportedOperationException("MessageProducer.send to undefined AMQP resource"));
}
if (msg instanceof RMQBytesMessage || msg instanceof RMQTextMessage) {
try {
AMQP.BasicProperties.Builder bob = new AMQP.BasicProperties.Builder();
bob.contentType("application/octet-stream");
bob.deliveryMode(RMQMessage.rmqDeliveryMode(deliveryMode));
bob.priority(priority);
bob.expiration(rmqExpiration(timeToLive));
bob.headers(msg.toAmqpHeaders());
bob = amqpPropertiesCustomiser.apply(bob, msg);
byte[] data = msg.toAmqpByteArray();
this.session.getChannel().basicPublish(destination.getAmqpExchangeName(), destination.getAmqpRoutingKey(), bob.build(), data);
} catch (IOException x) {
throw new RMQJMSException(x);
}
} else {
this.logger.error("Unsupported message type {} for AMQP destination {}", msg.getClass().getName(), destination);
throw new RMQJMSException("Unsupported message type for AMQP destination", new UnsupportedOperationException("MessageProducer.send to AMQP resource: Message not Text or Bytes"));
}
}
use of com.rabbitmq.jms.client.message.RMQTextMessage in project rabbitmq-jms-client by rabbitmq.
the class SelectedTopicMessageIT method testSendAndReceiveTextMessages.
@Test
public void testSendAndReceiveTextMessages() throws Exception {
topicConn.start();
TopicSession topicSession = topicConn.createTopicSession(false, Session.DUPS_OK_ACKNOWLEDGE);
Topic topic = topicSession.createTopic(TOPIC_NAME);
TopicPublisher sender = topicSession.createPublisher(topic);
TopicSubscriber receiver1 = topicSession.createSubscriber(topic, "boolProp", false);
TopicSubscriber receiver2 = topicSession.createSubscriber(topic, "not boolProp", false);
sender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message1 = topicSession.createTextMessage(MESSAGE1);
TextMessage message2 = topicSession.createTextMessage(MESSAGE2);
message1.setBooleanProperty("boolProp", true);
message2.setBooleanProperty("boolProp", false);
sender.send(message1);
sender.send(message2);
RMQTextMessage tmsg1 = (RMQTextMessage) receiver1.receive();
RMQTextMessage tmsg2 = (RMQTextMessage) receiver2.receive();
String t1 = tmsg1.getText();
String t2 = tmsg2.getText();
assertEquals(MESSAGE1, t1);
assertEquals(MESSAGE2, t2);
}
use of com.rabbitmq.jms.client.message.RMQTextMessage in project rabbitmq-jms-client by rabbitmq.
the class RMQMessageProducerTest method preferMessagePropertyMessagePropertiesSpecified.
@Test
public void preferMessagePropertyMessagePropertiesSpecified() throws Exception {
StubRMQMessageProducer producer = new StubRMQMessageProducer(session, destination, false);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.setPriority(9);
producer.setTimeToLive(1000L);
RMQTextMessage message = new RMQTextMessage();
message.setJMSPriority(1);
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
long expiration = System.currentTimeMillis() + 10 * 1000;
message.setJMSExpiration(expiration);
producer.send(message);
assertEquals(DeliveryMode.PERSISTENT, message.getJMSDeliveryMode());
assertEquals(1, message.getJMSPriority());
assertEquals(expiration, message.getJMSExpiration());
}
use of com.rabbitmq.jms.client.message.RMQTextMessage in project rabbitmq-jms-client by rabbitmq.
the class RMQMessageProducerTest method preferProducerPropertyNoMessagePropertySpecified.
@Test
public void preferProducerPropertyNoMessagePropertySpecified() throws Exception {
StubRMQMessageProducer producer = new StubRMQMessageProducer(session, destination, true);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.setPriority(9);
producer.setTimeToLive(1000L);
RMQTextMessage message = new RMQTextMessage();
producer.send(message);
assertEquals(DeliveryMode.NON_PERSISTENT, message.getJMSDeliveryMode());
assertEquals(9, message.getJMSPriority());
assertTrue(message.getJMSExpiration() > System.currentTimeMillis());
}
use of com.rabbitmq.jms.client.message.RMQTextMessage in project rabbitmq-jms-client by rabbitmq.
the class RMQMessageProducerTest method preferProducerPropertyMessagePropertiesSpecified.
@Test
public void preferProducerPropertyMessagePropertiesSpecified() throws Exception {
StubRMQMessageProducer producer = new StubRMQMessageProducer(session, destination, true);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.setPriority(9);
producer.setTimeToLive(1000L);
RMQTextMessage message = new RMQTextMessage();
message.setJMSPriority(1);
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
message.setJMSExpiration(System.currentTimeMillis() + 10 * 1000);
producer.send(message);
assertEquals(DeliveryMode.NON_PERSISTENT, message.getJMSDeliveryMode());
assertEquals(9, message.getJMSPriority());
assertTrue(message.getJMSExpiration() > System.currentTimeMillis());
}
Aggregations