NServiceBus offers four levels of consistency guarantees with regards to message processing. Levels availability depends on the selected transport. The default consistency level is TransactionScope (Distributed Transaction), but a different level can be specified using code configuration API.
See the Transports Transactions article to learn more about NServiceBus consistency guarantees.
By default, the transaction timeout limit is set to 10 minutes. See the Override the System.Transactions default timeout of 10 minutes article to learn how to adjust that value.
In Windows, the Distributed Transaction Coordinator (DTC) is an OS-level service which manages transactions that span across multiple resources, e.g. queues and databases.
The DTCPing tool is very useful for verifying that DTC service is configured correctly, as well as for troubleshooting:
For more information refer to the Troubleshooting MSDTC issues with the DTCPing tool article on MSDN.
DTCPing WARNING: The CID Values for Both Test Machines Are the Samemessage appears when running the DTCPing tool, the reason might be that the machine name is longer than 14 characters. For DTCPing and MSDTC to work, the machine name should be shorter than 15 characters.
Messages are processed in NServiceBus in the following steps:
- The queue is peeked to see if there's a message.
- If there's a message then transaction is started.
- The queue is contacted again to receive a message. This is because multiple threads may have peeked the same message. The queue makes sure only one thread actually gets a given message.
- If the thread is able to get it, NServiceBus tries to deserialize the message. If it fails, the message moves to the configured error queue and the transaction commits.
- After a successful deserialization, NServiceBus invokes all infrastructure, message mutators and handlers. An exception in this step causes the transaction to roll back and the message to return to the input queue. The message will be re-sent for a configured number of times, if all attempts fail then it'll be moved to the error queue.
Refer to the Message Handling Pipeline article to learn more about message processing.