This behavior was introduced with Camel Version 3.12 Previously (3.11) it works as expected.
I have created a Bug Ticket: https://issues.apache.org/jira/browse/CAMEL-17514 Am Mi., 19. Jan. 2022 um 12:10 Uhr schrieb Michael Rambichler < mich...@rambichler.at>: > Hi together, > > I hope you can give me a hint / solution to mitigate our Problem. > > We use MDCLogging and BreadcrumbIds. > But if we use in our Errorhandling e.g. an Custom OnExceptionProcessor the > MDC Value [camel.breadcrumb] is not set anymore. > > Is this a camel bug or do we misunderstand something? > The strange thing: If I use a custom UnitOfWorkFactory it works as > expected. But I would assume that If MDCLogging is enabled then the > DefaultUnitOfWork would handle this. > > Please see my example below. > > *Simple Routebuilder (with MDCLogging set):* > > @Override > public void configure() throws Exception { > > getContext().setUseMDCLogging(true); > getContext().setUseBreadcrumb(true); > > DeadLetterChannelBuilder errorHandlerBuilder = new > DeadLetterChannelBuilder(); > errorHandlerBuilder.setDeadLetterUri("direct:deadletterTest"); > errorHandlerBuilder.setOnExceptionOccurred(onExceptionProcessor); > errorHandler(errorHandlerBuilder); > > from("timer://foo?fixedRate=true&period=10000") > .log("Received exchange with breadcrumbID: > ${in.headers.breadcrumbId}") > .process(exchange -> { > LOG.info("Process with bug"); > throw new Exception("Some Bug"); > }); > > from("direct:deadletterTest") > .log("Deadletter received ${body}"); > > } > > *OnExceptionProcessor:* > > @Component > public class OnExceptionProcessor implements Processor { > > private static final Logger LOG = > LoggerFactory.getLogger(OnExceptionProcessor.class); > > @Override > public void process(Exchange exchange) throws Exception { > LOG.info("Some OnException process"); > } > } > > *Log without MDC camel.Breadcrumb:* > 2022-01-19 12:01:00,335 INFO [1 - timer://foo] route1 > [route1 0141fbc5-bb47-4458-a982-1e6585109b8a] - Received > exchange with breadcrumbID: 0141fbc5-bb47-4458-a982-1e6585109b8a > 2022-01-19 12:01:00,337 INFO [1 - timer://foo] > c.t.a.r.h.HelloBreadcrumbRoute [route1 > 0141fbc5-bb47-4458-a982-1e6585109b8a] - Process with bug > 2022-01-19 12:01:00,338 INFO [1 - timer://foo] > c.t.a.r.h.OnExceptionProcessor [****breadcrumbMissing**** ] - > Some OnException process > 2022-01-19 12:01:00,344 INFO [1 - timer://foo] route2 > [route2 ****breadcrumbMissing****] - Deadletter receive > > > > *Example of Custom UnitOfWork as workaround:* > > public class CustomUnitOfWork extends DefaultUnitOfWork { > > CustomUnitOfWork(Exchange exchange) { > super(exchange); > } > > @Override > public AsyncCallback beforeProcess(Processor processor, Exchange > exchange, AsyncCallback callback) { > > String breadcrumbId = > exchange.getIn().getHeader(Exchange.BREADCRUMB_ID, String.class); > if (breadcrumbId != null) { > MDC.put(MDC_BREADCRUMB_ID, breadcrumbId); > } > > return super.beforeProcess(processor, exchange, callback); > } > > > > >