6 Replies Latest reply on Aug 4, 2011 10:43 AM by davsclaus

    Transactions + camel + activemq?

    jamie3_james.archibald

      I am creating a new post as my previous post wasn't marked as a question. As mentioned earlier I have a case where I send messages to a JMS queue which the consumer receives the message and throws an exception, thus making the transaction fail. For some reason the client who sent the message to the queue never gets notified that the consumer failed. Instead the producer client receives a timeout exception after ~20 seconds.

       

      For example:

       

       

      from("direct:somewhere")

         .to("activemq:queue:destination")

       

       

      from("activemq:queue:destination")

         .transacted()

         .process(new Processor() {

            // client should receive exception immediately but instead we get a JMS timeout exception

            throw new RuntimeException("transaction failed");

        });

       

      link to my previous post

       

      http://fusesource.com/forums/thread.jspa?threadID=3159&tstart=0

        • 1. Re: Transactions + camel + activemq?
          njiang

          If you mark the route as .transacted(), when you throw the exception from your process, the jms template will not commit the transaction, and the message will still in the queue.

           

          It makes senesce that you get the timeout exception.

           

          Willem

          • 2. Re: Transactions + camel + activemq?
            davsclaus

            You need to enable transferException to use the exception as the reply.

            See more details at

            http://camel.apache.org/jms

             

            from("direct:somewhere")
            .to("activemq:queue:destination?transferException=true")
            
            from("activemq:queue:destination?transferException=true")
            .process(new Processor() {
            // client should receive exception immediately but instead we get a JMS timeout exception
            throw new RuntimeException("transaction failed");
            });
            

             

            • 3. Re: Transactions + camel + activemq?
              jamie3_james.archibald

              The "transferException=true" parameter worked once it was placed on the consumer and producer. Previously I only had it set on the consumer side and it didn't work.

               

              Much thanks

              • 4. Re: Transactions + camel + activemq?
                davsclaus

                Yeah I think you need it on both sides. The producer so it knows that an exception may be returned in the JMS message. And on the consumer side, so it knows, that it should send back the exception in the JMS message.

                • 5. Re: Transactions + camel + activemq?
                  jamie3_james.archibald

                  Would be good to make sure in the documentation it says to add it to the consumer and producer.

                   

                   

                  Also I have one more question. In the above example my transacted POJO throws PSQLExceptions which are serialized and sent back to the client. however the client doesn't have the PSQLException class in its classpath so I get class not found exceptions and in turn a timeout still occurs.

                   

                  Is there a way to tell camel how to transfer the exchange? Ideally I dont want to transfer the PSQLException back to the client, but instead maybe a RuntimeException. This could be executed in some custom code.

                  • 6. Re: Transactions + camel + activemq?
                    davsclaus

                    You can use onException on the broker side to catch and handle that PSQLExcpetion and set some other kind of exception.