Internal transactions are simpler thant DTC transactions. They are called internal because they are handled entirely inside the MSMQ code. They don’t rely on any support from MS DTC or any other transactional mechanism.
Internal transactions have a very simple programming model. Assuming, I want to receive, in at most two seconds, either two messages or not to receive any messages at all, I can write the following code:
try { mq.BeginTransaction(); messageA = mq.Receive(1000); messageB = mq.Receive(1000); mq.CommitTransaction(); } catch(Exception e) { mq.RollbackTransaction(); }
This is pretty simple. The problem is that internal MSMQ transactions cannot include database operations. So, for example if I would like to receive a message from a message queue and put the message in a database – all of these as one transaction – I would have to use external transactions.
namespace System.Messaging { public class MessageQueue { //. . . public void BeginTransaction(); public void CommitTransaction(); public void RollbackTransaction(); //. . . } }
Method | Explanation |
---|---|
BeginTransaction | Creates a new Microsoft Message Queue Server (MSMQ) internal transaction. |
CommitTransaction | Commits a pending internal transaction. |
RollbackTransaction | Rolls back the pending internal transaction. |