You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by bigbear <st...@gmail.com> on 2011/03/11 07:34:08 UTC

activemq rollback

Hi,

My env:
Camel: 2.6
ActiveMQ: 5.4.2
GlassFish: 2.2.1

I have the following route which gets a message from a topic and then stores
it in the database after some processing.
I added a dummy processor at the end which does nothing but throw a runtime
exception in order to test the rollback of JTA transaction spawning JMS and
JPA.
=============================
from("activemq:topic:patientTopic?clientId=myClientId&durableSubscriptionName=myDurableSubscriptionName")
.transacted()
.process(someProcessor)
.to("jpa:my.jpa.entity.class.name")
.process(new Processor() {

    public void process(Exchange arg0) throws Exception {

        throw new RuntimeException();

    }
});
=============================

Here is the relevant spring/camel config:

=============================
<!-- transaction manager -->
    <tx:jta-transaction-manager />

<!-- jpa -->
    <bean id="jpa" class="org.apache.camel.component.jpa.JpaComponent">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <bean id="entityManagerFactory"

 class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="persist" />
        <property name="jpaVendorAdapter" ref="jpaAdapter" />
        <property name="jpaProperties">
            <props>
                <prop
key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory
                </prop>
                <prop
key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.SunONETransactionManagerLookup
                </prop>
            </props>
        </property>
    </bean>


    <bean id="jpaAdapter"

 class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform"
value="org.hibernate.dialect.Oracle9Dialect" />
        <property name="database" value="ORACLE" />
        <property name="showSql" value="true" />
    </bean>

<!-- jms -->
    <bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="connectionFactory" ref="activemqXaConnectionFactory"
/>
        <property name="transacted" value="true" />
        <property name="transactionManager" ref="transactionManager" />
    </bean>

    <bean id="activemqXaConnectionFactory"
class="org.apache.activemq.ActiveMQXAConnectionFactory">
        <property name="brokerURL" value="tcp://localhost:61616" />
    </bean>
=============================

Looking at the logs the exception seems to have triggered a rollback
correctly.

DEBUG jta.JtaTransactionManager: Creating new transaction with name [null]:
PROPAGATION_REQUIRED,ISOLATION_DEFAULT
DEBUG support.TransactionSynchronizationManager: Initializing transaction
synchronization
DEBUG listener.DefaultMessageListenerContainer: Received message of type
[class org.apache.activemq.command.ActiveMQTextMessage] from consumer
[ActiveMQMessageConsumer { value=ID:tester01-53456-1299799024359-0:1:1:1,
started=true }] of session [ActiveMQSession
{id=ID:tester01-53456-1299799024359-0:1:1,started=true}]
DEBUG support.TransactionSynchronizationManager: Bound value
[org.springframework.jms.listener.LocallyExposedJmsResourceHolder@28b89e]
for key [org.apache.activemq.ActiveMQXAConnectionFactory@8306a3] to thread
[DefaultMessageListenerContainer-1]
DEBUG jta.JtaTransactionManager: Participating in existing transaction
DEBUG jta.JtaTransactionManager: Participating in existing transaction
DEBUG jpa.EntityManagerFactoryUtils: Opening JPA EntityManager
DEBUG jpa.EntityManagerFactoryUtils: Registering transaction synchronization
for JPA EntityManager
DEBUG support.TransactionSynchronizationManager: Bound value
[org.springframework.orm.jpa.EntityManagerHolder@634ff3] for key
[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@2ea80a]
to thread [DefaultMessageListenerContainer-1]
DEBUG support.TransactionTemplate: Initiating transaction rollback on
application exception
org.apache.camel.RuntimeCamelException: java.lang.Exception
    at
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1139)
    at
org.apache.camel.spring.spi.TransactionErrorHandler$1.doInTransactionWithoutResult(TransactionErrorHandler.java:178)
    at
org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)
    at
org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
    ......
    ......
[10/03/11 06:18:47:047 EST] DEBUG jta.JtaTransactionManager: Participating
transaction failed - marking existing transaction as rollback-only
[10/03/11 06:18:47:047 EST] DEBUG jta.JtaTransactionManager: Setting JTA
transaction rollback-only
====================================================

My understanding is that in this case the message is redelivered. But it is
not.
The message seems to be dequeued as well (looking at the ActiveMQ's web
admin console).

Any ideas/suggestions will be appreciated.

Thanks!