On the MSMQ newsgroups, Chris asked:
"I'm dropping messages into a queue on a local machine. Is there a way to easily send them to a remote server queue when they get received from the initial queue?"
Frank Boyne, our favourite MVP, proposed the following novel solution:
Before you send the message:
- set PROPID_M_ACKNOWLEDGE to MQMSG_ACKNOWLEDGMENT_FULL_RECEIVE
- set the PROPID_M_ADMIN_QUEUE and PROPID_M_ADMIN_QUEUE_LEN to point to the remote server queue.
Now send the message to the initial queue. When it is received, a positive acknowledgement message will be sent to the queue identified by the PROPID_M_ADMIN_QUEUE property. That acknowledegement message will be a copy of the original with the Class property set to a value that indicates that it is a positive acknowledgement.
The main drawbacks to this approach are:
- the class property is overwritten so your application cannot make use of it
- you'll also get negative acknowledgement messages (e.g. if the Time To Be Received timer expires before the message is received or if the queue is purged by an administrator) so the program processing messages in the remote server queue needs to look for negative acknowledgement messages and handle them appropriately.
- the original sending program cannot use either the admin queue mechanism or the acknowledgement mechanisms because we've hijacked them for this new use.
Great lateral thinking, Frank.