2
votes

Using NServiceBus with the NHibernate saga persister, how can I avoid duplicate sagas when it's possible for a message to be received more than once?

Here are some solutions that I've thought of so far:

  1. Never call MarkAsComplete() so the deduplication is handled in the usual fashion by the saga itself.

  2. Implement my own saga persister which stores the correlation ids for completed sagas so duplicate/additional messages are ignored.

1

1 Answers

2
votes

The question is what would cause the message to be received multiple times - is it due to retries of the same message (like in the case where there was a deadlock in the DB)? Those kinds of retries (causing the same message to be "processed" multiple times) are already handled by the transactional nature of NServiceBus.

If the situation is due to the message being sent by some other endpoint multiple times, the recommendation would be to see what you could do to prevent that on the sending side. If that isn't possible, then yes, a saga that doesn't ever complete could serve as your filter.