How to use remote transaction MSMQ?

I am writing a Windows service that retrieves messages from MSMQ and sends them to a legacy system (Baan). If the message failed or the machine descended during the message, I do not want to lose the message. Therefore, I use MSMQ transactions. I abort failure, and I am sure of success.

When working with a local queue, this code works well. But in the production process, I want to separate the machine (or machines) that starts the service from the queue itself. When I test the remote queue, a System.Messaging.MessageQueueException error occurs: "Transaction usage is invalid."

I checked that the specified queue is transactional.

Here is the code that gets from the queue:

// Begin a transaction. _currentTransaction = new MessageQueueTransaction(); _currentTransaction.Begin(); Message message = queue.Receive(wait ? _queueTimeout : TimeSpan.Zero, _currentTransaction); _logger.Info("Received a message on queue {0}: {1}.", queue.Path, message.Label); WORK_ITEM item = (WORK_ITEM)message.Body; return item; 

Answer

Since then, I have switched to SQL Service Broker . It supports remote transactional reception, while MSMQ 3.0 does not. And as an added bonus, he already uses an instance of SQL Server, which we are clustering and backing up.

+6
transactions msmq
source share
5 answers

I left a comment asking about the version of MSMQ you are using, as I think this is causing your problem. Transactional ingest was not implemented in earlier versions of MSMQ. If so, then this post explains your options.

+4
source share

Using TransactionScope should work provided that MSDTC works on both machines.

 MessageQueue queue = new MessageQueue("myqueue"); using (TransactionScope tx = new TransactionScope()) { Message message = queue.Receive(MessageQueueTransactionType.Automatic); tx.Complete(); } 
+3
source share

Since then, I have switched to SQL Service Broker . It supports remote transactional reception, while MSMQ 3.0 does not. And as an added bonus, he already uses an instance of SQL Server, which we are clustering and backing up.

0
source share

To use the transaction scope, you must verify that the MSDTC is enabled and that the remote client connection has been activated.

Installing MSDTC is not a problem, but activating the remote client connection requires a server reboot (on Windows Server 2003 it is).

Perhaps this post may help you: How to activate the MSDTC and remote client connection

0
source share

Aviod using remote MSMQ (another upgrade to MSMQ 4.0 to support remote MSMQ transaction). 1) Alternatively, you can create one web service for entering messages 2) Create a local MSMQ for transaction purposes 3) Create a small utility that has a batch (batch) number and messagenumbers ... After the packet fails, delete the messages in the other target, do it as a transaction scope

0
source share

All Articles