Is there any way (other than enrolling in a distributed transaction) to avoid the Saga data to be saved to RavenDB in NServiceBus if an exception happens in the End method of a Unit of Work?
I setup NSB 4.1 to not use the DTC
NServiceBus.Configure.Transactions
.Enable()
.Advanced(action => action.DisableDistributedTransactions());
I have a SqlUnitOfWork that when committing the changes to database might fail because of some constraint or timeout or something unexpected in the database.
public class SqlUnitOfWork : IManageUnitsOfWork
{
...
public void End(Exception ex = null)
{
if (ex == null)
datacontext.SubmitChanges(); //this could throw an exception
}
}
When an exception happens there the message is retried but the saga already is saved to ravendb. The workaround I found was not using the Unit of Work and submitting the changes at the end of the Handle method of the message handler however that doesn't work well when a transport message have multiple logical messages.
Is there a smart way to accomplish this?