How to pass automatically metadata from command to event?

Hi
I implemented command message interceptor which adds something to command message metadata. I can get this value in command handler using @MetaDataValue.

How can I get this value in event handler? It works when I apply event with metadata e.g. apply(event, metadata);
Can I add something to commands metadata and get it in event handler without rewriting in aggregate?

I have thought that it works like that by default.

Regards
Filip

Hi Filip.

you can pass information from one message to another using CorrelationDataProviders. If you’re on Spring Boot, just define one or more beans of type CorrelationDataProvider. It’s a simple interface with a single method, which defines which meta data entries to add to outgoing messages, based on the (meta data of the) message being handled.
By default, you get the MessageOriginProvider, which attaches correlationId and traceId. Note that you don’t get it if you explicitly define your own. If you also want the MessageOriginProvider, you will need to define that as a bean as well.

If you’re not on Spring Boot, you can use the Configurer to register your CorrelationDataProviders.

Cheers,

Allard