I have a flow
that starts with a poller
and hands off the message to several async
flows downstream using task-executors
to execute in parallel
for a given dataset. A downstream aggregator
completes the flow and notifies the poller that the flow
is complete.
I would like to track
every execution of the poller by using MDC
so that the logs
can be mapped to a particular execution of the flow
.
I started by adding MDC
to the poller thread (using Advice
), however with this approach there could be a couple of issues:
- How do I stamp the
MDC
on the executor thread when theasync
hand off happens? - Since executor uses a a
thread pool
, do I need to clear theMDC
before thethread
returns to the pool? Will there be any side effects?
Another approach would be to add MDC
to the Message
header and set it manually on the new thread
during the async
handoff. How to do that? For example, if I turn on the debug
logs, the MDC
should be stamped right from the beginning of the new thread
execution and not from the point where my logic starts in the service activator
.
How to set this on the task-executor
thread (and probably also remove before returning to the pool) using XML
configuration? Something like an MdcAwareThreadPoolExecutor
seen here.
Also, I would not want the MDC
logic to be spread across all the async
handoff endpoints, may be there is some generic way to configure it?
Is there a better way to achieve this? Any known solutions?