Propagating correlation data through scheduled events?

If you have a CorrelationDataProvider registered, Axon automatically propagates metadata from one message to the next as the application publishes them.

But it seems like the chain is broken when the workflow involves a scheduled event. Nothing in the event scheduler knows how to pull correlation data out of the message that's currently being processed, so you lose out on the convenient automatic propagation.

How are other people dealing with this, if at all?

One option is to have the application code explicitly populate the metadata when it schedules the event, but that seems like it could get unwieldy fast.

Another idea is to do it with message interceptors and thread-local variables: something that pulls out the correlation data before the event/command handler is called and stashes it into a ThreadLocal, and then a wrapper around the event scheduler that looks at the ThreadLocal and adds to the scheduled event's metadata. If the application starts a new UnitOfWork, it'll have to clear the correlation data if needed.

Any other approaches I should consider?

-Steve

Hi Steven,

this is based on Axon 2 code, right?
What we did in Axon 3, is make the Unit of Work responsible for providing the correlation data (based on providers that have been configured with it). That’s because the Unit of Work is aware of the message that is being processed in it, and the constructors of the messages (except for the copy-constructor) will check an available unit of work for meta-data that should be attached.
So effectively, it’s using ThreadLocal (in this case the Unit of Work) to transport meta data from the incoming event, to all outgoing events. So you last idea isn’t all that crazy…

Ever considered attempting a migration to Axon 3?

Allard