Skip to content

Latest commit

 

History

History
52 lines (33 loc) · 3 KB

transactions.md

File metadata and controls

52 lines (33 loc) · 3 KB
title summary reviewed component redirects
Transaction support
The design and implementation details of SQL Server transport transaction support
2024-12-28
SqlTransport
nservicebus/sqlserver/transactions
transports/sqlserver/transactions

The SQL Server transport supports the following transport transaction modes:

  • Transaction scope (distributed transaction)
  • Transport transaction - Send atomic with receive
  • Transport transaction - receive only
  • Unreliable (transactions disabled)

TransactionScope mode is beneficial as it enables exactly once message processing with distributed transactions. However, when transport, persistence, and business data are all stored in a single SQL Server catalog, it is possible to achieve exactly-once message delivery without distributed transactions. For more details, refer to the SQL Server native integration sample.

Note

Exactly once message processing without distributed transactions can be achieved with any transport using the Outbox feature. It requires business and persistence data to share the storage mechanism but does not put any requirements on transport data storage.

Transaction scope

partial: ambient-core-warning

In this mode, the ambient transaction is started before receiving the message. The transaction encompasses all processing stages, including user and saga data access.

If either the configured NServiceBus persistence mechanism or the user data access also supports transactions via TransactionScope, the ambient transaction could be promoted to a distributed transaction.

Note

Distributed transactions require Microsoft Distributed Transaction Coordinator (MSDTC) or Azure SQL Elastic Transactions.

Note

If the persistence mechanisms use SQL Server 2008 or later as an underlying data store and the connection strings configured for the SQL Server transport and the persistence are exactly the same, there will be no DTC escalation as SQL Server can handle multiple sequentially opened and closed connections via a local transaction.

include: mssql-dtc-warning

See also a sample covering this mode of operation using either SQL Persistence or NHibernate Persistence.

Native transactions

In this mode, the message is received inside a native ADO.NET transaction.

partial: native

Unreliable (transactions disabled)

In this mode, when a message is received, it is immediately removed from the input queue. If processing fails, the message is lost because the operation cannot be rolled back. Any other operation performed when processing the message is executed without a transaction and cannot be rolled back. This can lead to undesired side effects when message processing fails partway through.

partial: custom-connection-and-transaction