camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From triswork <tristan.k...@gmail.com>
Subject JTA Transactions not rolling back in RouteBuilder
Date Sat, 09 May 2009 06:38:56 GMT

Hi

I am hoping someone can tell me what I am doing wrong here... I cannot get
transaction rollbacks to work in my Camel routes and I have tried everything
I can think of.

I have created a new component that consumes messages from a database table.
The messages are deleted, but a status flag is updated). These messages need
to be placed into a JMS queue. If an exception/fault occurs along the way,
the database updates must be rolled back and the JMS message must not be
committed. 

The funny thing is that I can get JMS/JDBC rollbacks to work fine outside of
my routes - leading me to believe that I am doing something daft with my
custom component. The main difference is that I use the @Transactional
annotation outside my Route. Inside the route, I have tried to rely on
setting the SpringTransactionPolicy as per the examples in:
http://camel.apache.org/transactional-client.html. 
My problem route looks like this:
from(mmq:test).policy(required).to(activemq:test)
Without any annotations in my component, the Spring debug output shows the
following:
DEBUG - JtaTransactionManager      - Creating new transaction with name
[null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT

I suspect that the [null] is a big part of the problem, but I can't find a
way to make is not null.

My component is extremely simple. I create a consumer that extends
ScheduledPollConsumer.
The poll() method looks like this:

@Override
protected void poll() throws Exception {
    List<Map> queueItems = messageService.processQueue();
    for (Map q : queueItems) {
        Exchange exchange = endpoint.createExchange();
        exchange.getIn().setBody(q);
        getProcessor().process(exchange);
    }
}

The processQueue() method returns batches of 20 queue items at a time (i.e.
20 exchanges are created every time poll() is called).

I am using Glassfish JPA for transaction management, ActiveMQ as a message
broker and the Spring SimpleJdbcTemplate for database access. T


My Spring config is fairly straight forward:

Transaction Manager
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManagerName"
value="java:appserver/TransactionManager"/>
        <property name="allowCustomIsolationLevels" value="true"/>
</bean>

ActiveMQ
<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
        <property name="connectionFactory" ref="activeMQConnectionFactory"/>
        <property name="transactionManager" ref="transactionManager"/>
        <property name="transacted" value="true"/>
        <property name="concurrentConsumers" value="1"/>
</bean>

<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="configuration" ref="jmsConfig"/>
</bean>

<jee:jndi-lookup id="activeMQConnectionFactory"
jndi-name="jms/ActiveMQConnectionFactory"/> (This is configured to use XA
transactions within Glassfish)

JDBC DataSource (JNDI Lookup From Glassfish) (This is configured to use XA
transactions within Glassfish)
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/MyDataSource"/> 

My Custom Component
<bean id="messageService" class="org.test.services.MessageService">
        <property name="dataSource" ref="dataSource"/>
</bean>

<bean id="mmq" class="org.test.camel.component.mmq.MMQComponent">
        <property name="messageService" ref="messageService"/>
</bean>
-- 
View this message in context: http://www.nabble.com/JTA-Transactions-not-rolling-back-in-RouteBuilder-tp23457761p23457761.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.


Mime
View raw message