1
votes

I am creating a web application that is going to send messages using NServiceBus, and also write to a database. I want this to be an atomic operation, i.e. a transaction, so I wrap the code in a using new TransactionScope() statement.

When configuring NServiceBus you can call the IsTransactional-method. When do I pass 'false' to this method, and when is 'true' appropriate?

1

1 Answers

2
votes

IsTransactional(true) mean that all incoming messages will be processed within a transactionscope

http://docs.particular.net/nservicebus/architecture/ http://docs.particular.net/nservicebus/architecture/principles

For sends (outgoing messages) you need to create your own transaction scope to make sure that you're consitent with your database. Usually it's a good idea to move the actual processing (like writing to the database) to backend processes. If you do that NServiceBus will handle things like retries, exception management etc for you.

More about that here:

http://www.make-awesome.com/2010/10/why-not-publish-nservicebus-messages-from-a-web-application/