attach MetaData in HandlerInterceptor

Hello,
It’s simple to attach MetaData to message in DispatchInterceptor. I’m finding the way how to do that in HandlerInterceptor (and if it’s good idea). I’d like to call external service and enrich message with some MetaData.
What I see as an adept is
`
UnitOfWork.transformMessage()

`

Is this correct?

Hi Lukas,

correct. In a HandlerInterceptor, you need to transform the message in the unit of work. Note that other components processing (a copy of) the message, will not see the transformed result. Are you planning to use this additional meta data in your handlers, or is it meant to be attached to messages sent by these handlers only?

Cheers,

Allard

Hi Allard,
I need to have MetaData with “enriched data” inside Aggregate. So probably the command handler (on aggregate or separate one) need to have those MetaData. Will it be available there? What are the options?

thanks

Hi Lukas,

if you need the meta data entries in your aggregate, then the handler interceptor is the best way to get it assigned to the message. If you needed the information in outgoing messages only (for example events published by the aggregate), then you should use the handler interceptor to assign correlation data to the current unit of work instead.

Another option to get the data in your aggregate is by calling the external service in your aggregate. The disadvantage of that approach, though, is that you fetch the information while holding a lock on the aggregate, blocking all other commands for that aggregate. That may, or may not be an issue. Conceptually, it’s a bit nicer, though.

Cheers,

Allard