0

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?

Ajadex
  • 2,319
  • 1
  • 20
  • 23
  • What do you mean by logical messages? NSB will dispatch to the handler for each message inside a transport message, so you should be OK. – Adam Fyles Oct 30 '13 at 17:02
  • By logical messages I meant the messages encapsulated inside the transport message. Lets say I have a transport message with two messages inside. The first one call SubmitChanges correctly but with the second one an exception happens. After 5 retries the whole transport message will be moved to the error queue (containing the message that went through and the one that didn't). – Ajadex Oct 30 '13 at 17:52
  • 1
    I don't think there is a better way to do it. I think that is the trade off of not using DTC in the current version. You would have to maintain the state of the transaction yourself. I believe NSB 5 will be handling that scenario. – Adam Fyles Oct 31 '13 at 17:15

0 Answers0