Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing Whether a Remote MessageQueue Exists (using C#)

Tags:

c#

msmq

How can I tell whether a remote message queue exists? The documentation states that the "Exists" method does not work for remote machines.

The following is not valid (I know the queue path is accurate since I am able to send messages to the queue):

if (!MessageQueue.Exists(@"FormatName:Direct=TCP:192.168.2.58\Private$\MyQueue"))
  throw new InvalidOperationException("Queue does not exist");

The problem is that sending a message to a network address that does not have a listening queue behind it does not cause an exception. Having an exception thrown for an invalid queue address is critical to our application.

like image 919
user89166 Avatar asked Jun 18 '09 01:06

user89166


1 Answers

There is an article about this:

Frank's alternative approach is to make use of other features that MSMQ provides, such as negative acknowledgements messages with administration queues.

What should happen is that either:

  • the message will be delivered successfully to the destination queue
  • a negative acknowledgement (NACK) will be returned to the administration queue with a class of "The destination queue does not exist." (MQMSG_CLASS_NACK_BAD_DST_Q) Alternatively you could use negative source journaling and, on failure to deliver, should see the same class of NACK in the corresponding "Dead-letter messages" system queue.

In summary, don't check if the queue exists but instead handle the non-delivery of the message should it turn out that the queue doesn't exist.

http://blogs.msdn.com/johnbreakwell/archive/2008/07/31/checking-if-msmq-queues-exist-is-hard-work-so-should-you-bother.aspx

like image 96
Tetraneutron Avatar answered Sep 28 '22 05:09

Tetraneutron