You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by abdiels <ab...@gmail.com> on 2013/09/04 00:01:31 UTC

Issue with Transactions and Split

Guys,

    I am having an issue with split and sending messages to the a queue.  I
am reading from a queue in this example and sending to another queue each of
the split messages.  The first message goes in the destination queue, but
the I make the second message fail.  I was expecting that it will cause the
first message to go back to the original queue; however, since ActiveMQ is
trying to redeliver 6 times, I end up with 7 in the destination queue and
the original message in the DLQ.  Those 7 are the first message from the
split 7 times...the first one and then the 6 retries since I am using
shareUnitOfWork the orignal message goes to DLQ and since it retries it 6
times, the first message ends up making it in the destination queue 1 + 6
times so I end up with 7.  I get what is going on, but wondering if the
first split message should not be rolled back.  This example I got from the
camel book and made my own modification to simulate what I am trying to
accomplish.  Here is the sample code.  Here are the routes:

        from("activemq:queue:a")
            .transacted()
           
.split(body().tokenize(",")).streaming().shareUnitOfWork().stopOnException()
                .to("direct:quote")
                .to("activemq:queue:b")
            .end()
        ;

        from("direct:quote")
            .choice()
                .when(body().contains("Camel"))
                    .transform(constant("Camel rocks"))
                .when(body().contains("Donkey"))
                    .throwException(new IllegalArgumentException("Donkeys
not allowed"))
            .otherwise()
                .transform(body().prepend("Hello "))
        ;

This is the test that I am using to run it...the test code is not very
complete...I am not asserting anything just browsing the ActiveMQ queues
after it has run.

   @Test
    public void testWithCamel() throws Exception {
        context.start();
        template.sendBody("activemq:queue:a", "Camel,Donkey");
        //Object reply = consumer.receiveBody("activemq:queue:b", 10000);
        Thread.sleep(60000);
        //assertEquals("Camel rocks", reply);
    }

I was expecting here that Camel will be rolledback out of the queue once
Donkey fails, but that does not seem to the be case even sharing the unit of
work and stopping on Exception.  I am wondering if this is possible to do or
at the moment it hit the queue the transaction is gone...it seems to be one
transaction per split message and not one transaction for the whole thing.

Please let me know how I can accomplish this.  I am using Camel 2.11.0 and
ActiveMQ 5.8.0

Thank you!!



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-Transactions-and-Split-tp5738618.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with Transactions and Split

Posted by gquintana <ge...@gmail.com>.
- You can receive only one message per transaction (at least with Spring
DMLC), but can send many
- The transaction should wrap the whole route as long you don't change
thread (paralllelProcessing)
- You mat set transacted=true and transactionManager in your ActiveMQ
endpoints:
 
from("activemq:queue:a?transaction=true&transactionManager=#jmsTransactionManager") 
- shareUnitOfWork seems useless in your case




--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-Transactions-and-Split-tp5738618p5740942.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with Transactions and Split

Posted by Baris Acar <ba...@acar.org.uk>.
The comment in the link below - if true - indicates that the jms component (which the activemq component is based on) is "not designed for batched transactions" and doesn't support consuming multiple messages in a single transaction; I don't know whether that also means it won't post a batch of messages in a single Tx, or not.

http://camel.465427.n5.nabble.com/Consuming-multiple-JMS-messages-in-one-single-transaction-td5640489.html

It's not even clear to me, if you didn't have the split (so 1 msg in=1 msg out), whether the send takes place in the same transaction as the consume or not. 

Camel experts - can a local transaction span multiple operations, if those operations -- in this case, a consume and a produce -- are against the same resource (jms broker)? It's unclear to me, especially when there's a split(), how many transactions there are and when they get committed.

Barış

> On 4 Oct 2013, at 18:08, abdiels <ab...@gmail.com> wrote:
> 
> First let me thank you for replying...Here is what I have in my XML
> 
> 
>    <bean id="activemq"
> class="org.apache.activemq.camel.component.ActiveMQComponent">
> 
>        <property name="transacted" value="true"/>
> 
>        <property name="transactionManager" ref="txManager"/>
>    </bean>
> 
> 
>    <bean id="txManager"
> class="org.springframework.jms.connection.JmsTransactionManager">
> 
>        <property name="connectionFactory" ref="jmsConnectionFactory"/>
>    </bean>
> 
> 
>    <bean id="jmsConnectionFactory"
> class="org.apache.activemq.ActiveMQConnectionFactory">
>        <property name="brokerURL" value="tcp://localhost:61616"/>
>    </bean>
> 
> let me know if you need any additional information.
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Issue-with-Transactions-and-Split-tp5738618p5740889.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with Transactions and Split

Posted by abdiels <ab...@gmail.com>.
First let me thank you for replying...Here is what I have in my XML

    
    <bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
        
        <property name="transacted" value="true"/>
        
        <property name="transactionManager" ref="txManager"/>
    </bean>

    
    <bean id="txManager"
class="org.springframework.jms.connection.JmsTransactionManager">
        
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
    </bean>

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

let me know if you need any additional information.



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-Transactions-and-Split-tp5738618p5740889.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with Transactions and Split

Posted by gquintana <ge...@gmail.com>.
How did you declare the transaction manager? Something like:




--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-Transactions-and-Split-tp5738618p5740888.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue with Transactions and Split

Posted by abdiels <ab...@gmail.com>.
Any ideas?  Any advice?  Do I need to add more information?  Wrong place to
post?  Any feedback would be appreciated.



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-with-Transactions-and-Split-tp5738618p5740825.html
Sent from the Camel - Users mailing list archive at Nabble.com.