Federico Mariani created CAMEL-24069:
----------------------------------------

             Summary: camel-spring-rabbitmq - asyncConsumer failures are 
dropped because the endpoint exception handler is used instead of the consumer 
exception handler
                 Key: CAMEL-24069
                 URL: https://issues.apache.org/jira/browse/CAMEL-24069
             Project: Camel
          Issue Type: Bug
          Components: camel-spring-rabbitmq
    Affects Versions: 4.22.0
            Reporter: Federico Mariani


When {{asyncConsumer=true}} and an exchange fails after the listener method has 
already returned (asynchronous completion), 
{{EndpointMessageListener$EndpointMessageListenerAsyncCallback.done()}} reports 
the failure via the endpoint-level exception handler:

{code:java}
} else {
    // we were done async, so use the endpoint error handler
    if (endpoint.getExceptionHandler() != null) {
        endpoint.getExceptionHandler().handleException(rce);
    }
}
{code}

{{endpoint.getExceptionHandler()}} is {{null}} unless the user explicitly 
configured {{exceptionHandler}} on the endpoint, and there is no fallback - so 
the exception is dropped. At this point the message has already been 
acknowledged (the Spring listener container acks when {{onMessage}} returns), 
so no redelivery / retry-interceptor / DLQ handling can apply either.

Failures that pass through the route error handler are at least logged there, 
but failures that do not - e.g. an exception thrown while *sending the reply* 
of an InOut exchange, or the rollback wrapper - disappear without a single log 
line.

The listener should fall back to the *consumer's* exception handler: 
{{DefaultConsumer}} always has one (defaulting to {{LoggingExceptionHandler}}), 
and {{EndpointMessageListener}} already holds the consumer reference. For 
comparison, camel-jms in the equivalent code path calls 
{{endpoint.getErrorHandler().handleError(rce)}}, which is a guaranteed non-null 
logging handler.

Attached unit test (no broker needed) registers a recording exception handler 
on the consumer, drives {{EndpointMessageListener.onMessage}} with an 
async-failing processor, and fails on current main because the handler is never 
invoked:
{noformat}
async failure should be passed to the consumer exception handler ==> expected: 
<false> but was: <true> within 5 seconds.
{noformat}

----
_This issue was found during an AI-assisted code review of 
camel-spring-rabbitmq: Claude Code on behalf of Federico Mariani (fmariani). A 
failing unit test reproducing the issue is attached._



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to