use of javax.jms.MessageProducer in project wildfly-camel by wildfly-extras.
the class JMSIntegrationTest method testMessageConsumerRouteWithClientAck.
@Test
public void testMessageConsumerRouteWithClientAck() throws Exception {
final List<String> result = new ArrayList<>();
final CountDownLatch latch = new CountDownLatch(3);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
fromF("jms:queue:%s?connectionFactory=ConnectionFactory&acknowledgementModeName=CLIENT_ACKNOWLEDGE", QUEUE_NAME).process(exchange -> {
JmsMessage in = (JmsMessage) exchange.getIn();
Session session = in.getJmsSession();
TextMessage message = (TextMessage) in.getJmsMessage();
long count = latch.getCount();
try {
// always append the message text
result.add(message.getText() + " " + (4 - count));
if (count == 3) {
// do nothing on first
// note, this message is still acked because of
// [CAMEL-8749] JMS message always acknowledged even with CLIENT_ACKNOWLEDGE
} else if (count == 2) {
// recover causing a redelivery
session.recover();
} else {
// acknowledge
message.acknowledge();
}
} catch (JMSException ex) {
result.add(ex.getMessage());
}
latch.countDown();
}).transform(simple("Hello ${body}")).to("seda:end");
}
});
camelctx.start();
PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer();
consumer.start();
try {
// Send a message to the queue
ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory");
Connection connection = cfactory.createConnection();
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
connection.start();
Destination destination = (Destination) initialctx.lookup(QUEUE_JNDI_NAME);
MessageProducer producer = session.createProducer(destination);
try {
producer.send(session.createTextMessage("Kermit"));
producer.send(session.createTextMessage("Piggy"));
Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
Assert.assertEquals("Four messages", 3, result.size());
Assert.assertEquals("Kermit 1", result.get(0));
Assert.assertEquals("Piggy 2", result.get(1));
Assert.assertEquals("Piggy 3", result.get(2));
} finally {
connection.close();
}
} finally {
camelctx.stop();
}
}
use of javax.jms.MessageProducer in project wildfly-camel by wildfly-extras.
the class SJMSIntegrationTest method sendMessage.
private void sendMessage(Connection connection, String jndiName, String message) throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = (Destination) initialctx.lookup(jndiName);
MessageProducer producer = session.createProducer(destination);
TextMessage msg = session.createTextMessage(message);
producer.send(msg);
connection.start();
}
use of javax.jms.MessageProducer in project UVMS-Docker by UnionVMS.
the class MessageHelper method sendMessage.
public static void sendMessage(String queueName, final String msg) throws Exception {
String responseQueueName = queueName + "Response" + UUID.randomUUID().toString().replaceAll("-", "");
Connection connection = connectionFactory.createConnection();
connection.setClientID(UUID.randomUUID().toString());
final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
final Queue queue = session.createQueue(queueName);
final MessageProducer messageProducer = session.createProducer(queue);
messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
messageProducer.setTimeToLive(1000000000);
final Queue responseQueue = session.createQueue(responseQueueName);
TextMessage createTextMessage = session.createTextMessage(msg);
createTextMessage.setJMSReplyTo(responseQueue);
messageProducer.send(createTextMessage);
session.close();
connection.close();
}
use of javax.jms.MessageProducer in project wildfly-camel by wildfly-extras.
the class ActiveMQIntegrationTest method sendMessage.
private void sendMessage(Connection connection, String message) throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(QUEUE_NAME);
MessageProducer producer = session.createProducer(destination);
TextMessage msg = session.createTextMessage(message);
producer.send(msg);
connection.start();
}
use of javax.jms.MessageProducer in project tesb-rt-se by Talend.
the class JMSHttpBookStore method postOneWayBook.
private void postOneWayBook(Session session, Destination destination, Book book) throws Exception {
MessageProducer producer = session.createProducer(destination);
TextMessage message = session.createTextMessage();
message.setText(writeBook(book));
producer.send(message);
producer.close();
}
Aggregations