Remove dependency on MSDTC

Hello, I’m using NServiceBus 7 with SqlPersistence (but also using NHibernate) and SQS/SNS as the messaging system.

I’m trying to migrate our system to a linux server and need to remove the dependency on MSDTC. I’ve configured the outbox but in the case of duplicate messages, the outbox record is rolled back, but the corresponding data persisted by the handler is not rolled back.

I want to somehow share the transaction used by the outbox with my handlers.
I’ve read about the SynchronizedStorageSession, but the examples mainly show it being accessed by the business code in the handlers directly. I have too many handlers for this to be a feasible solution.

I would like to use the SynchronizedStorageSession at the pipeline level, if possible.
I’ve been trying to somehow use a Behavior<IInvokeHandlerContext> to pass the SynchronizedStorageSession into my NHibernate session factory, but haven’t gotten it to work (yet?). I can pass the connection into the session factory but haven’t found a way to pass the transaction, and as such, my code throws an exception at runtime indicating there’s no active transaction.

So, I have two main questions.

  1. Does this sound like the right approach?
  2. Do any of you know of a way to share the transaction from the SynchronizedStorageSession with the NHibernate session factory?

Thanks in advance!

@JamesGreenIsland,

Yes, using a behavior is the right approach if you don’t want to update the code of all your handlers.

From this paragraph, it looks like you already have all the required code in your behavior…

Try enabling Transaction Scope in the outbox settings

var outboxSettings = endpointConfiguration.EnableOutbox();
outboxSettings.UseTransactionScope();

Now, when passing the existing connection to the NHibernate session factory it should automatically identify the underlying transaction.