Right way to configure distributed transactions in NServiceBus 6


(Yuri M) #1

Hello

Migrating code to NserviceBus 6. I use this code to configure handlers to use MSMQ protocol with distributed transactions in order to cover whole handler execution under the same transaction (sending messages and business data updates in sql server must be under the same transaction):

 var transport = endpointConfiguration.UseTransport<MsmqTransport>();
 transport.Transactions(TransportTransactionMode.TransactionScope);
 transport.TransactionScopeOptions(isolationLevel: IsolationLevel.ReadCommitted);

Is there any sense then in wrapping handlers in unit of work explicitly with this code in addition to the aforementioned code:

endpointConfiguration.UnitOfWork().WrapHandlersInATransactionScope(IsolationLevel.ReadCommitted);

I believe it makes no sense in my case, but just in case want you guys to confirm that it does not add anything new to how handler is supposed to run.


(Andreas Öhlund) #2

Correct, that makes no sense since the transport already wraps the entire processing pipeline in a TransactionScope when running in the TransportTransactionMode.TransactionScope mode.

https://docs.particular.net/transports/transactions?version=core_7#transactions-transaction-scope-distributed-transaction

The mentioned UoW can be useful when running in other modes or on transports that doesn’t support transaction scopes.

Cheers,

Andreas