Hi

I am trying to add a transaction policy to one of my camel routes and I keep
getting the following exception:

java.lang.ExceptionInInitializerError at
org.apache.camel.spring.spi.SpringTransactionPolicy.wrap(SpringTransactionPolicy.java:54)
...
Caused by: org.apache.camel.RuntimeCamelException: An Exchange Property
'transacted' has already been registered; its traits are: java.lang.Boolean
org.apache.camel.transacted (transacted)

I have no idea what is causing this and have been unable to resolve the
issue. The relevant parts of my Spring config are:

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

<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
        <property name="connectionFactory" ref="activeMQConnectionFactory"/>
        <property name="transactionManager" ref="transactionManager"/>
        <property name="transacted" value="true"/>
        <property name="deliveryPersistent" value="false"/>
</bean>

<bean id="PROPAGATION_REQUIRED"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
        <property name="transactionManager" ref="transactionManager"/>
</bean>


My route looks like:
Policy required = bean(SpringTransactionPolicy.class,
"PROPAGATION_REQUIRED");
from("mycomponent:test").policy(required).to("activemq:queue:Test");

MyComponent is a custom component that creates a ScheduledPollConsumer.
For the purposes of trying to get this to work, the poll() method looks
like:

protected void poll() {
        Map h = new HashMap();
        h.put("msgNo", 1);
        h.put("batchSize", batchSize);
        Exchange exchange = endpoint.createExchange();
        exchange.getIn().setBody(h);
        getProcessor().process(exchange);

        if (true) throw new RuntimeException("Stop!");

        Map h2 = new HashMap();
        h2.put("msgNo", 2);
        h2.put("batchSize", batchSize);
        Exchange exchange2 = endpoint.createExchange();
        exchange2.getIn().setBody(h2);
        getProcessor().process(exchange2);
}

It also uses the "standard" exchange class.

The basic idea is to create two JMS messages and send them to the "Test"
queue.
I am trying to get to a point where the above code will never write anything
to the test queue due to a transaction rollback().

Any thoughts on what I am doing wrong?
-- 
View this message in context: 
http://www.nabble.com/Transaction-Exception-tp23434439p23434439.html
Sent from the Camel - Users (activemq) mailing list archive at Nabble.com.

Reply via email to