0

I am trying to use an onException clause within my route that also has an aggregator in it. I was expecting that whenever an exception is thrown within the aggregate() method of my aggregator, the OnException clause should catch it, handle it and redeliver it. However, that doesnt seem to be happening. Can anyone please suggest where I am going wrong.

from("jms:queue:start?concurrentConsumers=10").routeId("testRoute")
        .onException(Exception.class).log("Exception caught").process(new Processor() {

            @Override
            public void process(Exchange exchange) throws Exception {
                logger.debug("****Exception caught***");

            }
        })
        .handled(true).maximumRedeliveries(-1).end()
        .transacted()
        .aggregate(header("correlationHeader"), new CustomAggregator())
        .completionSize(50).
    to("jms:queue:end");

where CustomAggregator is my aggregator and within its aggregate method I am throwing an Exception to test my exception handling.

Any help or suggestion appreciated.

LearnToLive
  • 462
  • 9
  • 25
  • Try adding a [global exception handler](http://camel.apache.org/exception-clause.html) to your route. Glancing at your DSL everything looks acceptable, although I wouldn't bother with both the [log EIP](http://camel.apache.org/logeip.html) statement and a custom processor that both output a log entry, just make the log EIP statement specify log levels. Finally, double check that your logging level is low enough to output DEBUG entries. A common "error" when logs aren't printing is that the log level is too restrictive. – ProgrammerDan Mar 24 '14 at 15:10
  • 1
    Why do you not rely on the JMS built-in redelivery possibilities? – Peter Keller Mar 24 '14 at 20:49
  • @ProgrammerDan: I do agree with your comment of redundant logging.This is a obfuscated version of my actual route, which I am using to test the error handling. – LearnToLive Mar 25 '14 at 13:50
  • @Peter: The reason I was trying to avoid the JMS built-in redelivery was because I do not want error messages in the log and also do not want rollback of all the transactions, only the transaction which failed should be rolled back. – LearnToLive Mar 25 '14 at 13:53
  • Your case sounds fairly complicated. If you aren't logging errors, are you at least going to use a dead letter queue to keep track of failure messages? I'm not sure why the exception strategy doesn't appear to work for you, but more details on your overall strategy might be necessary to help you. – ProgrammerDan Mar 25 '14 at 14:25
  • @LearnToLive Perhaps Camel fails do handle the exceptions as JMS does it already for you. And, yes, you definitely should just use the JMS features. Do not log the error messages if don't want them. And in JMS the transactions are rolled back only if something fails according to you needs. – Peter Keller Mar 26 '14 at 07:05

0 Answers0