Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-9606

SJMS Consumer-Producer in transaciton



    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.15.4, 2.16.2
    • 2.19.0
    • camel-sjms
    • None
    • Unknown


      I'm not 100% sure this is a bug but it feels that way from conversation I had via mailing lists.

      I'm trying to ensure transactional processing between SJMS consumer and producer (e.g. using same JMS session).

      In other words this simple case:
      1. prepare higher amount of JMS messages in broker (e.g. ActiveMQ with 1000 messages)
      2. use Camel route from input queue to output queue using trasacted=true
      3. start context (starts consuming messages) and in any time kill java process

      When I kill process, I would expect that sum of messages in input and output queue will be 1000 - so the transaction works. But what happens is that I always end up with 1001+ messages. Maybe it is misconfiguration of routes or misunderstanding how SJMS can work.

      I feel this is critical because JMS is generally used because it its transactional capabilities.

      Here is the sample code I used for reproduction (using ActiveMQ):

      public class SjmsTransaction {
          public static void main(String[] args) throws Exception {
              RouteBuilder rb = new RouteBuilder() {
                  public void configure() throws Exception {
              CamelContext context = new DefaultCamelContext();
              System.out.println("=====> Starting context");
              // Now the context will run and consume messages, when I kill application by force in any time
              // I expect this to be true: <#messagesInInputAtBeginning> == <#messagesInInputNow> + <#messagesInOutputNow>
              // What happens is that there is always < (e.g. I submitted 1000 messages, out has 500, in has 501)
          private static void addJmsComponent(CamelContext context) {
              ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
              ConnectionFactoryResource connResource = new ConnectionFactoryResource(5, factory);
              SjmsComponent comp = new SjmsComponent();
              context.addComponent("sjms", comp);
          private static Processor systemOut(final String message) {
              return new Processor() {
                  public void process(Exchange exchange) throws Exception {
                      System.out.println(exchange.getExchangeId() + ": " + message);

      Note that I tried to use it with various combinations of acknowledgeMode and In/InOut exchange pattern - but without luck.
      I'm not that much oriented in Camel source code but I found that JMS session is held within the exchange so probably when producer finds in an exchange existing JMS session and is configured to be transacted, then maybe it can participate this session? Or maybe there are other hooks (like Synchronization objects) in some registry that take care of this issue?

      Here is the link to the previous mailing list conversation: http://camel.465427.n5.nabble.com/SJMS-transaction-td5777522.html


        Issue Links



              acosentino Andrea Cosentino
              d1x Zdeněk Obst
              0 Vote for this issue
              4 Start watching this issue