gpt4 book ai didi

c# - 测试远程 MessageQueue 是否存在(使用 C#)

转载 作者:太空狗 更新时间:2023-10-29 20:35:39 25 4
gpt4 key购买 nike

我如何判断一个远程消息队列exists ?文档指出“存在”方法不适用于远程机器。

以下无效(我知道队列路径是准确的,因为我能够将消息发送到队列):

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

问题在于,向后面没有监听队列的网络地址发送消息不会导致异常。为无效队列地址抛出异常对我们的应用程序至关重要。

最佳答案

有一篇文章是关于这个的:

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

关于c# - 测试远程 MessageQueue 是否存在(使用 C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1010366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com