.net 写入远程 MSMQ

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6308668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:38:08  来源:igfitidea点击:

Writing to a remote MSMQ

.netwindowsmsmq

提问by Dan Appleyard

Okay, here is a very simple and fundamental question. If I have an application on windows machine A that wants to write to a queue on windows machine B, do I need to have MSMQ installed on machine A (even though there is no queue there)? I am just beginning to use queues for my applications and trying to figure some fundamentals out.

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

Thanks

谢谢

回答by stuartd

Yes, you need MSMQ installed locally to write to a remote queue. If you're writing to a private queue, take a look at this pagewhich has useful information on how to format the queue name. If you're writing to a remote Transactional queue, then you need to make sure you specify that correctly (point 5)

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

This is the article text:

这是文章正文:

1. When working with remote queues, the queue name in the format machinename\private$\queuenamedoesn'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).

1. 使用远程队列时,格式machinename\private$\queuename中的队列名称不起作用。这会导致“无效的队列路径”错误。

2. 队列名称必须提及为FormatName:Direct=OS:machinename\\private$\\queuename

这是必要的,因为队列访问仅使用格式名称语法在内部完成。另一个友好表示被转换为 FormatName,然后使用。使用远程队列时,除非有 AD 来解析队列名称,否则友好名称将不起作用。查看文档了解详细信息。

对于例如。

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

3. 继上一点之后,请注意 FormatName 区分大小写。如果您将前面的字符串提及为 FORMATNAME:Direct=OS:machinename\\private$\\queuename,它将不起作用。令人惊讶的是,在这种情况下没有抛出错误。字符串的“FormatName”部分似乎是唯一区分大小写的部分。其他人可能会出现在不同的情况下。例如。你可以写“直接”。

4. 如果您想使用机器的 IP 地址,语法将为FormatName:Direct=TCP:ipaddress\\private$\\queuename.

对于例如。

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

5. 您在代码中创建的队列实例的事务属性应与您尝试向其发送消息的队列的事务属性相匹配。因此,在前面的示例中,我将消息发送到非事务性队列。要发送到事务队列,代码将是

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

如果事务属性不匹配,则不会传递消息。令人惊讶的部分又是,我没有收到任何错误,消息就消失了

6. 最后,当您向远程队列发送消息时,会在您自己的机器上创建一个临时传出队列。这用于远程队列不可用的情况。如果您转到计算机管理控制台 (compmgmt.msc),并展开服务和应用程序/消息队列/传出队列,您将看到这些队列。控制台的右侧应显示详细信息,包括状态(已连接或未连接)和下一跳的 IP 地址。

回答by John Breakwell

All MSMQ communication requires an MSMQ queue manager at each end. MSMQ-using applications communicate with their local queue manager which does the work for them. MSMQ-using applications cannot communicate directly with any queues, local or remote.

所有 MSMQ 通信都需要在每一端都有一个 MSMQ 队列管理器。使用 MSMQ 的应用程序与其本地队列管理器通信,后者为它们完成工作。使用 MSMQ 的应用程序不能直接与任何本地或远程队列通信。

回答by Rendition

Another (instead of installing MSMQ on the local machine running the client) would be to implement a WCF service which takes its messages from an MSMQ queue. In that case, your remote client would only have to specify the remote service endpoint for it to write directly to the remote queue. You would also have to be careful that the security on the remote queue was set correctly.

另一个(而不是在运行客户端的本地机器上安装 MSMQ)是实现 WCF 服务,该服务从 MSMQ 队列中获取其消息。在这种情况下,您的远程客户端只需指定远程服务端点即可直接写入远程队列。您还必须注意远程队列的安全设置是否正确。

I think this would be a better way of implementing queue-based communication. This is a short answer, but I will happily expand if you're interested (I noticed that you were pretty happy with the other answer :)

我认为这将是实现基于队列的通信的更好方法。这是一个简短的答案,但如果您有兴趣,我会很乐意扩展(我注意到您对另一个答案非常满意:)

回答by abksharma

below format worked for us

以下格式对我们有用

key="PublicQueueName" value="FormatName:Direct=TCP:192.168.12.58\private$\myqueue"

Also you would require to give remote queue access permissions

您还需要授予远程队列访问权限

security: Allow Anonymus login

安全性:允许匿名登录

enter image description here

在此处输入图片说明