Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote MSMQ, Transactions and ReceiveById fails - "Message requested was not found in the queue specified"

I am getting an error "Message requested was not found in the queue specified" when using transactions in remote MSMQ. If transaction is removed or if the queue is moved to same machine, everything works just fine. The queue is on Windows 2008 machine and the client (code shown below) is run on Windows 7 machine.

//Throws above error                
using (MessageQueueTransaction mqTxn = new MessageQueueTransaction())
{
    mqTxn.Begin();

    Message message = messageQueue.ReceiveById(peekedMessage.Id, mqTxn);

    mqTxn.Abort();
}

//Throws above error
using (TransactionScope txnScope = new TransactionScope())
{
    Message message = messageQueue.ReceiveById(peekedMessage.Id, MessageQueueTransactionType.Automatic);
}

//Works fine
Message message = messageQueue.ReceiveById(peekedMessage.Id);

P.S. peekedMessage is messages peeked just before these calls. I have verified that the peekedMessage.Id matches with the first queue item. The queue is transactional.

like image 317
amit_g Avatar asked Dec 08 '10 01:12

amit_g


1 Answers

MessageQueueTransaction can only be used for internal transactions so it won't work in the remote queue case.

The second way (using TransactionScope) would work as it uses DTC. DTC should be running and properly configured on both ends. By default, DTC is turned off both in Windows 2008 and Windows 7. In addition if firewall is on, DTC is to be put in the exception list. As soon as that is done, it works like a charm.

like image 54
amit_g Avatar answered Nov 18 '22 23:11

amit_g