Search code examples
nservicebusnservicebus-sagas

What transactions are used in NServiceBus Sagas?


I'm using Azure Table storage for persistence and Azure Service Bus for transport and I would like to know what transactions are in place within a saga's handler? Is it the same as a normal handler?

I'm asking because I'm seeing database changes (SqlBulkCopy which normally enlists in the ambient transaction) happening multiple times. I'm accessing the database directly from the Saga in this scenario to 'single thread' the handling of the messages, but it doesn't seem to be working.


Solution

  • Azure Service Bus transport supports the following transport transactions levels only

    1. SendsAtomicWithReceive (default)
    2. ReceiveOnly
    3. None

    It does not support Transaction Scope level. Which is what you're looking for.

    Why is that? Azure Service Bus does not allow any ambient transaction to take place. Any business-related data operation will be excluded from the handler transaction. To avoid duplicate business data writes you will need to implement idempotency to ensure the same business data is not written more than once when messages are retried.