Is it necessary/wise to use Persistence with all NServiceBus projects? I am working on an integration that uses SQL Transport and only command messages. I’m not seeing the value of using Persistence, but I’m worried that I’m over looking something.
If you don’t use features require Persistence (https://docs.particular.net/persistence/) then you don’t have to use it. The SQL Transport version 6.0.0 requires persistence for:
- Gateway Deduplication
The previous versions could require Persistence for other features but this depends on using the specific version.
I don’t know your context and deployment scenario but from the consistency between messaging operations and data persistence point of view I think you may consider if you will need Outbox feature.
I’ve been reading about the Outbox feature. I’m finding it a bit confusing.
On one hand documentation suggests that it is used to guarantee ‘only once’ delivery of messages, meaning that it prevents messages from being sent again if it was already processed.
On the other hand it seems to suggest that it is used to guarantee ‘at least once’ delivery of messages, meaning that if some unexpected error occurred it guarantees we won’t lose any messages.
Are both of these things true? If so, outbox seems like a good thing to have in place.
The Outbox feature guarantees ‘at-least-once’ message delivery on the wire (transport) level so yes message won’t be lost but could be start processing more than once. You could think about it as executing message handler more than once for the same message (the same message id).
In the same time Outbox guarantees ‘exact-once’ message processing so even if message handler will be executing more than once for the same message (the same message id) the handler logic will be deduplicate and run only when the previous Outbox transaction execution wasn’t commit successfully.
Two things are important using Outbox:
- business data and outbox data must exist in the same database and required the same connection for persisting data
- outgoing messages could be send more than once so on the receiving side must be also some kind of deduplication mechanism for example…Outbox
One tip. If you use the same database for business data and SQL Transport you could use Persistence to achieve ‘exactly once’ message processing without Outbox feature. See https://docs.particular.net/samples/sqltransport-sqlpersistence/
Hope this help.