After doing a little bit more investigation, what happens (as I understand
this at least..) is the following:

1. TransactionErrorHandler.processInTransaction() delegates the routing of
the exchange to be executed within a transaction. 

            logTransactionBegin(redelivered, ids);

* // HERE the  transactionTemplate.execute(new
TransactionCallbackWithoutResult() {} is executed
// see next snippet of code
            doInTransactionTemplate(exchange);*

            logTransactionCommit(redelivered, ids);

        } catch (TransactionRollbackException e) {
            // do not set as exception, as its just a dummy exception to
force spring TX to rollback
            logTransactionRollback(redelivered, ids, null, true);
        } catch (Throwable e) {
            exchange.setException(e);
            logTransactionRollback(redelivered, ids, e, false);
        } finally {
            // mark the end of this transaction boundary
            exchange.getUnitOfWork().endTransactedBy(transactionKey);
        }

To do so Camel passes an anonymous inner class to the TX Transaction
template:

TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) 
{
 // here the Camel processors and whatever is in the Route definition is
executed
 // AND the OnException() handling!
 // this is executed within a transaction
}
}

Also the code of the *transactionTemplate.execute()* that executes the above
Callback.

        public <T> T execute(TransactionCallback<T> action) throws
TransactionException {
                if (this.transactionManager instanceof
CallbackPreferringPlatformTransactionManager) {
                        return ((CallbackPreferringPlatformTransactionManager)
this.transactionManager).execute(this, action);
                }
                else { 
                        *// here the exception is thrown, because DB is
down!*
                        TransactionStatus status = 
this.transactionManager.getTransaction(this);
                        T result;
                        try {
                                result = action.doInTransaction(status); *// 
the callback is executed
here*
                        }


The result is that the Camel TransactionCallbackWithoutResult (Camels
anonymous inner class), that does the routing of the exchange and the
execution of the OnException() is never executed.

Code executes the following catch statements:

 } catch (Throwable e) {
            exchange.setException(e);
            logTransactionRollback(redelivered, ids, e, false);
        } finally {
            // mark the end of this transaction boundary
            exchange.getUnitOfWork().endTransactedBy(transactionKey);
        }

Is this expected behavior? I ask this, because the most probable scenario
that a Camel user would want is to be able to handle this exception and
probably send an alert and/ or a message to a DLQ.

Any hint is more than welcome!

Thanks!










--
View this message in context: 
http://camel.465427.n5.nabble.com/Problem-with-exception-handler-onException-on-Camel-2-12-X-routes-tp5742605p5790824.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to