[ 
https://issues.apache.org/jira/browse/CAMEL-15957?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17263902#comment-17263902
 ] 

Shmakov Alexey commented on CAMEL-15957:
----------------------------------------

I founded solution:
{code:java}
// RouteBuilder::configure or another method before start CmaelContext
getContext().getManagementStrategy().addEventNotifier(new 
ExceptionEventNotifier());

static class ExceptionEventNotifier extends EventNotifierSupport {

    @Override
    public void notify(CamelEvent event) throws Exception {
        if (event instanceof CamelEvent.ExchangeFailureHandlingEvent) {
            Exchange exchange = 
((CamelEvent.ExchangeFailureHandlingEvent)event).getExchange();
            //We use just BREADCRUMB_ID in MDC, for all MDC headers put it here
            MDC.put(MDCUnitOfWork.MDC_BREADCRUMB_ID, 
exchange.getMessage().getHeader(Exchange.BREADCRUMB_ID, String.class));
        }
    }

    @Override
    public boolean isEnabled(CamelEvent event) {
        return ExchangeFailureHandling.equals(event.getType());
    }
}
{code}

> Exception in async producer and MDC context
> -------------------------------------------
>
>                 Key: CAMEL-15957
>                 URL: https://issues.apache.org/jira/browse/CAMEL-15957
>             Project: Camel
>          Issue Type: Bug
>    Affects Versions: 3.4.0
>            Reporter: Shmakov Alexey
>            Priority: Minor
>         Attachments: camel-async-test.zip
>
>
> If an exception occurs in the asynchronous producer, the MDC context is not 
> refreshed and MDC logging breaks. This situation occurs when the onException 
> block is processed in another thread, for example, if the external 
> http-server returned an error code when connecting through a ahc/cxf 
> component or a read timeout occurred



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to