gpt4 book ai didi

.net - 写入远程 MSMQ

转载 作者:可可西里 更新时间:2023-11-01 12:12:35 26 4
gpt4 key购买 nike

好的,这是一个非常简单和基本的问题。如果我在 Windows 机器 A 上有一个应用程序想要写入 Windows 机器 B 上的队列,我是否需要在机器 A 上安装 MSMQ(即使那里没有队列)?我刚刚开始为我的应用程序使用队列,并试图找出一些基础知识。

谢谢

最佳答案

是的,您需要在本地安装 MSMQ 才能写入远程队列。如果您正在写入私有(private)队列,请查看 this page其中包含有关如何格式化队列名称的有用信息。如果您正在写入远程事务队列,那么您需要确保正确指定(第 5 点)

这是文章正文:

1. When working with remote queues, the queue name in the format machinename\private$\queuename doesn't work. This results in an "invalid queue path" error.

2. The queue name has to be mentioned as FormatName:Direct=OS:machinename\\private$\\queuename.

This is necessary since the queue access is internally done using the format name syntax only. The other friendly representation is converted to the FormatName and then used. When working with remote queues, unless there is an AD to resolve the queue name, the friendly name won't work. Check out documentation for details.

For Eg.

MessageQueue rmQ = new MessageQueue 
("FormatName:Direct=OS:machinename\\private$\\queue");
rmQ.Send("sent to regular queue - Atul");

3. Further to previous point, note that FormatName is case sensitive. If you mention the earlier string as FORMATNAME:Direct=OS:machinename\\private$\\queuename, it won't work. Surprisingly, there is no error thrown in this case. "FormatName" part of the string seems to be the only case sensitive part. Others can appear in different case. For eg. You can write "DIRECT".

4. In case you want to use the machine's IP address the syntax will be FormatName:Direct=TCP:ipaddress\\private$\\queuename.

For Eg.

MessageQueue rmQ = new MessageQueue
("FormatName:Direct=TCP:121.0.0.1\\private$\\queue");
rmQ.Send("sent to regular queue - Atul");

5. The transactional properties of the queue instance you create in code should match with that of the queue you are trying to send the message to. So in the earlier examples, I was sending message to a non-transactional queue. To send to a transactional queue, the code would be

MessageQueue rmTxnQ = new MessageQueue
("FormatName:Direct=OS:machinename\\private$\\queue");
rmTxnQ.Send("sent to Txn queue - Atul", MessageQueueTransactionType.Single);

If the transactional properties don't match, the message will not be delivered. The surprising part is again, I didn't get any error, and the message just disappeared

6. Finally, when you send messages to remote queue, a temporary outgoing queue is created on your own machine. This is used in case the remote queue is unavailable. If you go to the computer Management console (compmgmt.msc), and expand the Services and Applications / Message Queuing / Outgoing Queues, you would see these queues. The right side of the console should show the details including the state (connected or not) and the IP address(es) for the next hop(s).

关于.net - 写入远程 MSMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6308668/

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