MessageOriginProvider usage

Hi when I register MessageOriginProvider with CommandBus how should it work?

I was playing with this sample . In this scenario

CreateBankTransferCommand ->
BankTransferCreatedEvent ->
(BankTransferManagementSaga) DebitSourceBankAccountCommand ->
SourceBankAccountDebitedEvent ->
(BankTransferManagementSaga) CreditDestinationBankAccountCommand ->
DestinationBankAccountCreditedEvent ->
(BankTransferManagementSaga) MarkBankTransferCompletedCommand

all events contains different correlationId and traceId. I can see that correlationId is unique for each message. How to achieve that all metadata will contain the same traceId? Where do I need to register MessageOriginProvider for saga?

On each EventProcessor you (manually) create, you should register a CorrelationDataInterceptor. On that interceptor, you can register all CorrelationDataProviders (of which OriginProvider is one). If you use the configuration API to define processors, these interceptors are registered automatically.

If you register this interceptor on all components that handle messages (CommandBus, Event Processor and perhaps some custom components that handle messages directly from the Event Bus/Store), then the traceId will be copied between all messages in the cause-effect chain.

Cheers,

Allard

Hi Allard,

I still don’t understand that. In this case, when I create only CommandBus by myself where do I need to register CorrelationDataInterceptor to have same traceId in all events ? I’ve updated the sample.

Thanks

Lukas

Hi Lukas,

the configuration of the Command Bus looks fine. With this configuration, do you still get the different Trace IDs?

Cheers,

Allard

Hi Allard,
yes traceid is still different can you look into this?

Thank you

Lukas

Hi Lukas,

I found some time to dive into this. It seems like the AuditDataProviders aren’t properly picked up for Sagas. They are for “regular” event handlers, just not for Saga instances.

As a workaround, temporarily, you will probably need to define your own processor (e.g. SubscribingProcessor) and SagaManager. On the processor, you can register the CorrelationDataInterceptor (which you also registered on the Command Bus).

Cheers,

Allard