MSMQ Transactional Remote Receive

I was recently implementing a Queuing solution where a client application was accessing a MSMQ Queue on a remote server.

Here are few links describing the feature in MSMQ:

Outside of setting up the environment properly the main issue I faced was how do you actually code against it.

My original implementation was something like:

using (var transaction = new MessageQueueTransaction())
{
transaction.Begin();
var message = _queue.Receive(transaction);
// message processing...
transaction.Commit();
}

This would end up with a MessageQueueException and the following message: “The transaction operations sequence is invalid.” :\

The reason is that to get transaction remote receives to work I had to use a DTC transaction as follow:

using (var scope = new TransactionScope())
{
var message = _queue.Receive(MessageQueueTransactionType.Automatic);
// message processing...
scope.Complete();
}

From here, I could listen to a remote queue and still keep my processing transactional!

Categories CodeTags , , ,

1 thought on “MSMQ Transactional Remote Receive

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close