Search code examples
apache-camelspring-camel

JMSComponent>transacted=true and transacted() in camel builder


How transacted() in camel DSL is related to transacted="true" of JMSComponent. Will that make any sense, if transacted property of JMSComponent is set to "true" along with transacted() in camel DSL ?


Solution

  • transacted="true" in JMS component configuration makes your JMS consumer transacted. So this is required if you want to make sure you don't lose messages.

    However, you have multiple options to enable transactions (see the Camel docs for details).

    1. Use local JMS transactions
    2. Use your own Spring transaction manager

    The Camel DSL transacted() is only necessary if you go with the second option, it references a SpringTransactionPolicy (for example PROPAGATION_REQUIRED). If it is present in your route, Camel is looking for a Spring transaction manager to use.

    If you use option 1 (what is simpler in configuration and perfectly suitable if you only talk to a single JMS broker), you don't need the Camel DSL transacted() and your JMS consumer routes are nevertheless transactional.

    Addition due to comments

    To use option 1, you only have to set transacted="true" and lazyCreateTransactionManager="false" on your Camel ActiveMQComponent. You must not configure a Spring transaction manager (if you do, you end up with two tx managers!)

    If you want to be transactional between multiple JMS brokers or a broker and a Database, you would either need XA transactions or you have to implement compensation logic to handle the edge cases when using simple transactions with each system involved.