JMS Sample - 6.3

Talend ESB Mediation Developer Guide

Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Design and Development
Talend ESB

In this sample we want to listen for messages on a queue and process the messages with our business logic Java code and send them along. Since it is based on a unit test the destination is a mock endpoint.

First we configure the standard Spring XML to declare a JMS connection factory, a JMS transaction manager and our ActiveMQ component that we use in our routing.

<!-- setup JMS connection factory -->
<bean id="jmsConnectionFactory" 
   <property name="brokerURL" 

<!-- setup Spring jms TX manager -->
<bean id="jmsTransactionManager" 
   <property name="connectionFactory" ref="jmsConnectionFactory"/>

<!-- define our activemq component -->
<bean id="activemq" 
   <property name="connectionFactory" ref="jmsConnectionFactory"/>
   <!-- define the jms consumer/producer as transacted -->
   <property name="transacted" value="true"/>
   <!-- setup the transaction manager to use -->
   <!-- if not provided then Camel will automatically use a 
       JmsTransactionManager, however if you for instance use a JTA  
       transaction manager then you must configure it -->
   <property name="transactionManager" ref="jmsTransactionManager"/>

And then we configure our routes. Notice that all we have to do is mark the route as transacted using the transacted tag.

<camelContext xmlns="">
    <!-- disable JMX during testing -->
    <jmxAgent id="agent" disabled="true"/>
        <!-- 1: from the jms queue -->
        <from uri="activemq:queue:okay"/>
        <!-- 2: mark this route as transacted -->
        <!-- 3: call our business logic that is myProcessor -->
        <process ref="myProcessor"/>
        <!-- 4: if success then send it to the mock -->
        <to uri="mock:result"/>

<bean id="myProcessor" 
    class="org.apache.camel.component.jms.tx.JMSTransactionalClientTest \\ 


Which error handler? When a route is marked as transacted using transacted, Camel will automatically use the TransactionErrorHandler as Error Handler. It supports basically the same feature set as the DefaultErrorHandler, so you can for instance use Exception Clause as well.