Search in sources :

Example 6 with JmsMessage

use of org.apache.camel.component.jms.JmsMessage in project camel by apache.

the class JmsToFileMessageIdTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            // Make a route from an activemq queue to a file endpoint, then try to call getMessageId()
            from("activemq:foo").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // assert camel id is based on jms id 
                    String camelId = exchange.getIn().getMessageId();
                    assertNotNull(camelId);
                    JmsMessage jms = (JmsMessage) exchange.getIn();
                    String jmsId = jms.getJmsMessage().getJMSMessageID();
                    assertNotNull(jmsId);
                    assertEquals(jmsId, camelId);
                }
            }).to("file://target/tofile").process(new Processor() {

                public void process(Exchange exchange) {
                    // in Camel 1.4 or older this caused a NPE
                    assertNotNull(exchange.getIn().getMessageId());
                }
            }).to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) JmsMessage(org.apache.camel.component.jms.JmsMessage)

Aggregations

JmsMessage (org.apache.camel.component.jms.JmsMessage)6 Exchange (org.apache.camel.Exchange)5 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 Processor (org.apache.camel.Processor)4 JMSException (javax.jms.JMSException)2 Message (javax.jms.Message)2 Session (javax.jms.Session)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1 Destination (javax.jms.Destination)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 MessageProducer (javax.jms.MessageProducer)1 TextMessage (javax.jms.TextMessage)1 InitialContext (javax.naming.InitialContext)1 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)1