Grokbase Groups Camel users May 2011
FAQ
Hello,

I got an issue with JMS transactions when I try to route a message I'm
consumming to another queue.

When I kill the camel component using "kill -9" or "Ctrl-C", I
sometimes lost messages.

According to Camel/JMS DEBUG logs, it seems that the message is sent
to my second queue with a new transaction instead of using the one
created when receiving the message.

Here is an extract of my spring configuration :

------------------------------------------------------------------------------------
<bean id="required"
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="amqTransactionManager" />
<property name="propagationBehaviorName" value="PROPAGATION_MANDATORY" />
</bean>
<bean id="amqTransactionManager" name="amqTransactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="amqPoolConnectionFactory" />
</bean>
<bean id="amqPoolConnectionFactory"
class="org.jencks.amqpool.PooledConnectionFactory">
<constructor-arg ref="amqConnectionFactory" />
<property name="maxConnections" value="10" />
<property name="maximumActive" value="10" />
</bean>
<amq:connectionFactory id="amqConnectionFactory"
brokerURL="${bo.activemq.brokerurl}"
warnAboutUnstartedConnectionTimeout="1">
<property name="redeliveryPolicy" ref="transactedRedeliveryPolicy" />
<property name="transportListener" ref="jmsExceptionListener" />
<property name="exceptionListener" ref="jmsExceptionListener" />
</amq:connectionFactory>
<bean id="transactedRedeliveryPolicy"
class="org.apache.activemq.RedeliveryPolicy">
<property name="initialRedeliveryDelay" value="1000" />
<property name="maximumRedeliveries" value="5" />
<property name="useExponentialBackOff" value="true" />
</bean>

<camelContext id="ORDERS" shutdownRunningTask="CompleteCurrentTaskOnly"
xmlns="http://camel.apache.org/schema/spring">
<route id="ActiveMQ_ORDERS_TO_SCHEMA_VALIDATION">
<from ref="AMQ_ORDERS" />
<transacted ref="required"/>
<to ref="AMQ_ORDERS_2" />
</route>
</camelContext>
------------------------------------------------------------------------------------

Thanks a lot for any help you can offer !


Regards,

--
Céline

Search Discussions

  • Ashwin Karpe at May 9, 2011 at 12:01 pm
    Hi,

    Looks like you have not wired your amqTransactionManager correctly to your
    connectionFactory and hence the transaction is not properly wired to the JMS
    endpoint.

    Please check the example below.

    Cheers,

    Ashwin...

    ----------------------------------------------------
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring
    " rel="nofollow">http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext>
    <route>
    <from ref="activemq:queue:foo" />
    <transacted ref="required"/>
    <to ref="activemq:topic:bar" />
    </route>
    </camelContext>

    <bean id="jmsConnectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL"
    value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>

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

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

    <bean id="activemq2"
    class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL"
    value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>

    <bean id="required"
    class="org.apache.camel.spring.spi.SpringTransactionPolicy">
    <property name="transactionManager" ref="amqTransactionManager" />
    <property name="propagationBehaviorName"
    value="PROPAGATION_MANDATORY" />
    </bean>

    </beans>

    -----
    ---------------------------------------------------------
    Ashwin Karpe
    Apache Camel Committer & Sr Principal Consultant
    FUSESource (a Progress Software Corporation subsidiary)
    http://fusesource.com

    Blog: http://opensourceknowledge.blogspot.com
    CamelOne 2011: http://fusesource.com/camel2011
    ---------------------------------------------------------
    --
    View this message in context: http://camel.465427.n5.nabble.com/Problem-with-JMS-transaction-tp4381332p4381695.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Céline Bugaud at May 9, 2011 at 1:48 pm
    Hello Ashwin,

    Thank you for the quick reply !

    The only major difference I see between our configurations is that you
    create two differents ActiveMQComponent, one per queue. In my
    configurations the two queues are using the same ActiveMQComponent,
    configured with the transactionManager.

    Is that what I'm doing wrong ? Can't I have two queues using the same
    activeMQComponent ?

    In your exemple, the second ActiveMQComponent is not using any
    transactionManager, will he be used then inside the transactionManager
    of the first one ?

    Thanks again for your help, I'm quite new at this...

    Regards,

    --
    Céline
    On Mon, May 9, 2011 at 2:00 PM, Ashwin Karpe wrote:
    Hi,

    Looks like you have not wired your  amqTransactionManager correctly to your
    connectionFactory and hence the transaction is not properly wired to the JMS
    endpoint.

    Please check the example below.

    Cheers,

    Ashwin...

    ----------------------------------------------------
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring
    " rel="nofollow">http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext>
    <route>
    <from ref="activemq:queue:foo" />
    <transacted ref="required"/>
    <to ref="activemq:topic:bar" />
    </route>
    </camelContext>

    <bean id="jmsConnectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL"
    value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>

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

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

    <bean id="activemq2"
    class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL"
    value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>

    <bean id="required"
    class="org.apache.camel.spring.spi.SpringTransactionPolicy">
    <property name="transactionManager" ref="amqTransactionManager" />
    <property name="propagationBehaviorName"
    value="PROPAGATION_MANDATORY" />
    </bean>

    </beans>

    -----
    ---------------------------------------------------------
    Ashwin Karpe
    Apache Camel Committer & Sr Principal Consultant
    FUSESource (a Progress Software Corporation subsidiary)
    http://fusesource.com

    Blog: http://opensourceknowledge.blogspot.com
    CamelOne 2011: http://fusesource.com/camel2011
    ---------------------------------------------------------
    --
    View this message in context: http://camel.465427.n5.nabble.com/Problem-with-JMS-transaction-tp4381332p4381695.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Ashwin Karpe at May 9, 2011 at 8:44 pm
    Hi,

    Sorry about the confusion... You do not need the second connection factory
    "activemq2". This is an error on my part.

    The key difference in your setup vs mine is that there is a
    "transactionManager" property set in my ActiveMQ component and the
    "transacted" property is set to true . This wires in the transactional
    capability to the ActiveMQ component.

    Please see the corrected XML below.

    Cheers,

    Ashwin...



    =======================================
    ----------------------------------------------------
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring
    " rel="nofollow">http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext>
    <route>
    <from ref="activemq:queue:foo" />
    <transacted ref="required"/>
    <to ref="activemq:topic:bar" />
    </route>
    </camelContext>

    <bean id="jmsConnectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL"
    value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>

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

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

    <bean id="required"
    class="org.apache.camel.spring.spi.SpringTransactionPolicy">
    <property name="transactionManager" ref="amqTransactionManager" />
    <property name="propagationBehaviorName"
    value="PROPAGATION_MANDATORY" />
    </bean>

    </beans>

    -----
    ---------------------------------------------------------
    Ashwin Karpe
    Apache Camel Committer & Sr Principal Consultant
    FUSESource (a Progress Software Corporation subsidiary)
    http://fusesource.com

    Blog: http://opensourceknowledge.blogspot.com
    CamelOne 2011: http://fusesource.com/camel2011
    ---------------------------------------------------------
    --
    View this message in context: http://camel.465427.n5.nabble.com/Problem-with-JMS-transaction-tp4381332p4382912.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Céline Bugaud at May 10, 2011 at 6:38 am
    Hi Ashwin,

    I didn't sent my entire spring configuration, but my ActiveMQComponent
    was already linked to the transactionManager :

    ----------------------------------------------------
    <bean id="activemqPersistent"
    class="org.apache.activemq.camel.component.ActiveMQComponent"
    lazy-init="true">
    <property name="connectionFactory"
    ref="amqPoolConnectionFactory"/>
    <property name="transactionManager" ref="amqTransactionManager"/>
    <property name="transacted" value="true"/>
    <property name="brokerURL" value="${bo.activemq.brokerurl}" />
    <property name="acknowledgementModeName" value="CLIENT_ACKNOWLEDGE"/>
    <property name="maxConcurrentConsumers" value="10" />
    <property name="receiveTimeout" value="3000"/>
    <property name="maxMessagesPerTask" value="1"/>
    <property name="deliveryPersistent" value="true"/>
    <property name="usePooledConnection" value="true"/>
    <property name="testConnectionOnStartup" value="true"/>
    </bean>
    ----------------------------------------------------

    However, I tried using two different activeMQComponent, and that
    seemed to solve my problem : I no longer loose messages. The
    transaction does not seem to work well either : I now have duplicate
    messages.

    Regards,

    --
    Céline
    On Mon, May 9, 2011 at 10:43 PM, Ashwin Karpe wrote:
    Hi,

    Sorry about the confusion... You do not need the second connection factory
    "activemq2". This is an error on my part.

    The key difference in your setup vs mine is that there is a
    "transactionManager" property set in my ActiveMQ component and the
    "transacted" property is set to true . This wires in the transactional
    capability to the ActiveMQ component.

    Please see the corrected XML below.

    Cheers,

    Ashwin...



    =======================================
    ----------------------------------------------------
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring
    " rel="nofollow">http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext>
    <route>
    <from ref="activemq:queue:foo" />
    <transacted ref="required"/>
    <to ref="activemq:topic:bar" />
    </route>
    </camelContext>

    <bean id="jmsConnectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL"
    value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>

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

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

    <bean id="required"
    class="org.apache.camel.spring.spi.SpringTransactionPolicy">
    <property name="transactionManager" ref="amqTransactionManager" />
    <property name="propagationBehaviorName"
    value="PROPAGATION_MANDATORY" />
    </bean>

    </beans>
  • Claus Ibsen at May 10, 2011 at 6:40 am
    Remove this
    <property name="acknowledgementModeName" value="CLIENT_ACKNOWLEDGE"/>

    As when you use transacted=true, it has to use TRANSACTED_ACKNOWLEDGE.
    So do not override/change this setting.

    2011/5/10 Céline Bugaud <c.bugaud@gmail.com>:
    Hi Ashwin,

    I didn't sent my entire spring configuration, but my ActiveMQComponent
    was already linked to the transactionManager :

    ----------------------------------------------------
    <bean id="activemqPersistent"
    class="org.apache.activemq.camel.component.ActiveMQComponent"
    lazy-init="true">
    <property name="connectionFactory"
    ref="amqPoolConnectionFactory"/>
    <property name="transactionManager"       ref="amqTransactionManager"/>
    <property name="transacted"               value="true"/>
    <property name="brokerURL"                value="${bo.activemq.brokerurl}" />
    <property name="acknowledgementModeName"  value="CLIENT_ACKNOWLEDGE"/>
    <property name="maxConcurrentConsumers"   value="10" />
    <property name="receiveTimeout"           value="3000"/>
    <property name="maxMessagesPerTask"       value="1"/>
    <property name="deliveryPersistent"       value="true"/>
    <property name="usePooledConnection"      value="true"/>
    <property name="testConnectionOnStartup"  value="true"/>
    </bean>
    ----------------------------------------------------

    However, I tried using two different activeMQComponent, and that
    seemed to solve my problem : I no longer loose messages. The
    transaction does not seem to work well either : I now have duplicate
    messages.

    Regards,

    --
    Céline
    On Mon, May 9, 2011 at 10:43 PM, Ashwin Karpe wrote:
    Hi,

    Sorry about the confusion... You do not need the second connection factory
    "activemq2". This is an error on my part.

    The key difference in your setup vs mine is that there is a
    "transactionManager" property set in my ActiveMQ component and the
    "transacted" property is set to true . This wires in the transactional
    capability to the ActiveMQ component.

    Please see the corrected XML below.

    Cheers,

    Ashwin...



    =======================================
    ----------------------------------------------------
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring
    " rel="nofollow">http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext>
    <route>
    <from ref="activemq:queue:foo" />
    <transacted ref="required"/>
    <to ref="activemq:topic:bar" />
    </route>
    </camelContext>

    <bean id="jmsConnectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL"
    value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>

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

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

    <bean id="required"
    class="org.apache.camel.spring.spi.SpringTransactionPolicy">
    <property name="transactionManager" ref="amqTransactionManager" />
    <property name="propagationBehaviorName"
    value="PROPAGATION_MANDATORY" />
    </bean>

    </beans>


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    CamelOne 2011: http://fusesource.com/camelone2011/
    Twitter: davsclaus
    Blog: http://davsclaus.blogspot.com/
    Author of Camel in Action: http://www.manning.com/ibsen/
  • Céline Bugaud at May 10, 2011 at 7:37 am
    Hi,

    I just changed the settings to remove the property
    "acknowledgementModeName", and I still lost a message.

    I was able to reproduce the problem in a test project, I send its
    spring configuration as an attachement.
    On Tue, May 10, 2011 at 8:40 AM, Claus Ibsen wrote:
    Remove this
    <property name="acknowledgementModeName"  value="CLIENT_ACKNOWLEDGE"/>

    As when you use transacted=true, it has to use TRANSACTED_ACKNOWLEDGE.
    So do not override/change this setting.

    2011/5/10 Céline Bugaud <c.bugaud@gmail.com>:
    Hi Ashwin,

    I didn't sent my entire spring configuration, but my ActiveMQComponent
    was already linked to the transactionManager :

    ----------------------------------------------------
    <bean id="activemqPersistent"
    class="org.apache.activemq.camel.component.ActiveMQComponent"
    lazy-init="true">
    <property name="connectionFactory"
    ref="amqPoolConnectionFactory"/>
    <property name="transactionManager"       ref="amqTransactionManager"/>
    <property name="transacted"               value="true"/>
    <property name="brokerURL"                value="${bo.activemq.brokerurl}" />
    <property name="acknowledgementModeName"  value="CLIENT_ACKNOWLEDGE"/>
    <property name="maxConcurrentConsumers"   value="10" />
    <property name="receiveTimeout"           value="3000"/>
    <property name="maxMessagesPerTask"       value="1"/>
    <property name="deliveryPersistent"       value="true"/>
    <property name="usePooledConnection"      value="true"/>
    <property name="testConnectionOnStartup"  value="true"/>
    </bean>
    ----------------------------------------------------

    However, I tried using two different activeMQComponent, and that
    seemed to solve my problem : I no longer loose messages. The
    transaction does not seem to work well either : I now have duplicate
    messages.

    Regards,

    --
    Céline
    On Mon, May 9, 2011 at 10:43 PM, Ashwin Karpe wrote:
    Hi,

    Sorry about the confusion... You do not need the second connection factory
    "activemq2". This is an error on my part.

    The key difference in your setup vs mine is that there is a
    "transactionManager" property set in my ActiveMQ component and the
    "transacted" property is set to true . This wires in the transactional
    capability to the ActiveMQ component.

    Please see the corrected XML below.

    Cheers,

    Ashwin...



    =======================================
    ----------------------------------------------------
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://camel.apache.org/schema/spring
    " rel="nofollow">http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext>
    <route>
    <from ref="activemq:queue:foo" />
    <transacted ref="required"/>
    <to ref="activemq:topic:bar" />
    </route>
    </camelContext>

    <bean id="jmsConnectionFactory"
    class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL"
    value="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
    </bean>

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

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

    <bean id="required"
    class="org.apache.camel.spring.spi.SpringTransactionPolicy">
    <property name="transactionManager" ref="amqTransactionManager" />
    <property name="propagationBehaviorName"
    value="PROPAGATION_MANDATORY" />
    </bean>

    </beans>


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    CamelOne 2011: http://fusesource.com/camelone2011/
    Twitter: davsclaus
    Blog: http://davsclaus.blogspot.com/
    Author of Camel in Action: http://www.manning.com/ibsen/


    --
    Céline

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedMay 9, '11 at 8:26a
activeMay 10, '11 at 7:37a
posts7
users3
websitecamel.apache.org

People

Translate

site design / logo © 2022 Grokbase