camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <>
Subject Re: Using custom MDC values with Camel
Date Sun, 07 Sep 2014 06:29:54 GMT

There is a JIRA ticket about to support this in the future.

You can use a custom UoW factory and extend the MDC factory we have an
add the logic you need. And then configure Camel to use your factory.

On Fri, Sep 5, 2014 at 1:15 PM, Joni Nousiainen
<> wrote:
> Hi!
> My use case: I want name log files based on XML file names that I'm
> processing. E.g. if the file name is "sample.xml" log output would go
> to "incoming.xml.log".
> I have read about MDC support in Camel and Karaf, and based on that
> I've come up with a working solution: I put the XML file name into MDC
> in the beginning of the processing like so:
> public class PutIncomingFileNameToMDC {
>     private static final String MDC_KEY_FILE_NAME = "fileName";
>     public void putIncomingFileNameToMDC(
>             @Header(Exchange.FILE_NAME_ONLY) String fileName) {
>         MDC.put(MDC_KEY_FILE_NAME, fileName);
>     }
> }
> Then I specify MDCSiftingAppender in Karaf's configuration. This
> solution works OK until I use a splitter with
> parallelProcessing="true" on one of my routes. I did some digging and
> found class MDCUnitOfWork which seems to fix this for Camel's
> predefined MDC values (exchangeId etc) when useMDCLogging is set to
> "true" in Came context.
> Any suggestions how should I apply the fix to my own custom MDC value
> ("fileName")? Would it be possible to get built-in support for this in
> Camel somehow?
> Camel version: 2.12.4
> Karaf version: 2.3.5
> Java version: 1.7.0_51
> Platform: Windows
> BR,
> Joni Nousiainen

Claus Ibsen
Red Hat, Inc.
Twitter: davsclaus
Author of Camel in Action:

View raw message