SzymonPobiega / NServiceBus.Router

Cross-transport, cross-site and possibly cross-cloud router component for NServiceBus
MIT License
5 stars 10 forks source link

Sagas and ReplyToOriginator #11

Closed mteinum closed 4 years ago

mteinum commented 5 years ago

Hi!

The router is working fine when the message is processed by a handler. IHandleMessages/context.Reply and correlationId is not changed.

But, when the message is processed by a Saga, ReplyToOriginator will set the correlationid to the originating messageid.

Line 110:

https://github.com/Particular/NServiceBus/blob/65fee422bdd79a3e5d4adc3dcc40353cb5b9dd82/src/NServiceBus.Core/Sagas/Saga.cs

and line 11:

https://github.com/Particular/NServiceBus/blob/65fee422bdd79a3e5d4adc3dcc40353cb5b9dd82/src/NServiceBus.Core/Correlation/AttachCorrelationIdBehavior.cs

Any plans on supporting this scenario?

Adding TLV to the outgoing MessageId might solve this issue together with the CorrelationId.

SzymonPobiega commented 5 years ago

Hi @mteinum

Unfortunately this is a bug in NServiceBus itself. The Saga data does not include the CorrelationId of the original message so it applies the message ID instead.

What persistence do you use? With SQL persistence you might be able to work around this scenario using the metadata. With other persistences your would actually need to store the initial CorrelationId in the SagaData itself. I can help you craft the pipeline behaviors necessary to accomplish this.

Evad-s commented 5 years ago

Hi @SzymonPobiega,

I came across this issue the other day and resorted to using pub/sub instead, but I would be grateful if you could post how to get around this issue by storing the correlationid in SagaData and the subsequent alteration of the reply to enable this to work.

SzymonPobiega commented 5 years ago

@Evad-s

Here's the workaround:

Hope it helps.