use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.
the class SJMSIntegrationTest method testMessageConsumerRoute.
@Test
public void testMessageConsumerRoute() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("sjms:queue:" + QUEUE_NAME + "?connectionFactory=ConnectionFactory").transform(body().prepend("Hello ")).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();
try {
sendMessage(connection, QUEUE_JNDI_NAME, "Kermit");
String result = consumer.receive(3000).getIn().getBody(String.class);
Assert.assertEquals("Hello Kermit", result);
} finally {
connection.close();
}
} finally {
camelctx.stop();
}
}
use of org.apache.camel.PollingConsumer in project wildfly-camel by wildfly-extras.
the class JMSIntegrationTest method testCustomMessageConverter.
@Test
public void testCustomMessageConverter() throws Exception {
MessageConverter converter = new MessageConverter() {
@Override
public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException {
return null;
}
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
TextMessage originalMessage = (TextMessage) message;
TextMessage modifiedMessage = new ActiveMQTextMessage();
modifiedMessage.setText(originalMessage.getText() + " Modified");
return modifiedMessage;
}
};
initialctx.bind("messageConverter", converter);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
fromF("jms:queue:%s?connectionFactory=ConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME).transform(simple("Hello ${body.getText()}")).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();
try {
sendMessage(connection, QUEUE_JNDI_NAME, "Kermit");
String result = consumer.receive(3000).getIn().getBody(String.class);
Assert.assertEquals("Hello Kermit Modified", result);
} finally {
connection.close();
}
} finally {
camelctx.stop();
initialctx.unbind("messageConverter");
}
}
use of org.apache.camel.PollingConsumer in project wildfly-swarm by wildfly-swarm.
the class JMSIntegrationTest method testMessageConsumerRoute.
@Test
public void testMessageConsumerRoute() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jms:queue:" + Main.QUEUE_NAME + "?connectionFactory=ConnectionFactory").transform(body().prepend("Hello ")).to("direct:end");
}
});
camelctx.start();
PollingConsumer consumer = camelctx.getEndpoint("direct:end").createPollingConsumer();
consumer.start();
try {
// Send a message to the queue
InitialContext initialctx = new InitialContext();
ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory");
Connection connection = cfactory.createConnection();
try {
sendMessage(connection, Main.QUEUE_JNDI_NAME, "Kermit");
String result = consumer.receive().getIn().getBody(String.class);
Assert.assertEquals("Hello Kermit", result);
} finally {
connection.close();
}
} finally {
camelctx.stop();
}
}
Aggregations