1

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.

Carl
  • 1,782
  • 17
  • 24

1 Answers1

1

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.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • Thanks. I was under the impression that the normal handlers do include a transaction as when they fail the database changes are rolled back. Or have I missed an important point somewhere :) – Carl Aug 03 '19 at 11:11
  • You're correct, handlers participate in the transaction level defined for the endpoint. The level depends on the capabilities of the underlying transport. If you happen to use MSMQ or SQL Server Transport, then business data operations can participate in the same transaction as the transport. This is not the case for ASB, ASQ, ASQ, and RabbitMQ. – Sean Feldman Aug 03 '19 at 13:50
  • I see. But if I'm using one of the transports that doesn't support transactions, does the handler still use a transaction that is separate from the transport transaction? And if the answer to this is yes, then is that behaviour the same for handlers within a saga? – Carl Aug 04 '19 at 16:08
  • The handler is the subject to the transaction level set by the endpoint, which depends on the transport used. For example, with ASB transport you can have your own transaction in the handler, but it will be unrelated and entirely user specific. Standalone handlers and handlers for Sagas both follow this. BTW, it is *not* recommended to perform any work in the Saga handlers. Instead, you should send work requests to the stand-alone handlers. – Sean Feldman Aug 05 '19 at 00:01
  • Thanks a lot. Really helped to clear some of this up for me! – Carl Aug 05 '19 at 14:00