简体   繁体   English

从另一台计算机发送MSMQ消息

[英]Send MSMQ message from a different computer

I have a program that sends MSMQ messages to a remote machine. 我有一个程序将MSMQ消息发送到远程计算机。
This works fine. 这很好用。

However, during debugging we will run the program on a number of different machines, and on the remote server there is an issue receipting the message as the mappings etc. are not set up for our development machines. 但是,在调试期间,我们将在许多不同的机器上运行程序,并且在远程服务器上收到消息时会出现问题,因为没有为我们的开发机器设置映射等。

What I would like to do is be able to specify a machine to send the MSMQ messages from; 我想要做的是能够指定一台机器来发送MSMQ消息; one that has the required mappings so the remote machine would receipt messages correctly. 一个具有所需映射,以便远程机器正确接收消息。

Currently I create a queue using this path: FormatName:DIRECT=http://the.remote.machine.co.uk/msmq/frommycompany . 目前,我使用此路径创建一个队列: FormatName:DIRECT=http://the.remote.machine.co.uk/msmq/frommycompany

I then send messages by creating message objects and sending them within a transaction. 然后,我通过创建消息对象并在事务中发送消息来发送消息。

How can I send the messages to the remote machine from a machine other than the one the program is running on, so that the remote machine can receipt the messages correctly? 如何从运行程序的计算机以外的计算机将消息发送到远程计算机,以便远程计算机可以正确接收消息?

If I understood the problem correctly, I suggest to use a service that acts as a router. 如果我正确理解了问题,我建议使用充当路由器的服务。

You might want to use a WCF service that gets called by all clients from your development machines first and then acts itself as the only client who sends messages into your target machine. 您可能希望使用首先由开发计算机上的所有客户端调用的WCF服务 ,然后将其自身充当将消息发送到目标计算机的唯一客户端。 WCF is well suited to send the messages into the queue(s) with built-in functionality. WCF非常适合将消息发送到具有内置功能的队列中。

Alternatively - or in combination - you could consider using some messaging framework such as NServiceBus that makes your life working with MSMQ much easier. 或者 - 或者组合 - 您可以考虑使用一些消息传递框架,例如NServiceBus ,这使您的生活更容易使用MSMQ。

NServiceBus gives you a lot of flexibility to configure where your messages should go to and who should subscribe to them. NServiceBus为您提供了很大的灵活性来配置您的消息应该去哪里以及谁应该订阅它们。 Most this can simply be set up in the application configuration files. 大多数这可以简单地在应用程序配置文件中设置。

If i understand your question you want to send from machine one to a queue on machine 2. Given that is what you want to do try this: 如果我理解你的问题,你想从机器1发送到机器2上的队列。鉴于这是你想要做的尝试这个:

       System.Messaging.Message msg = new System.Messaging.Message();
        msg.Body = "This is a test message";
        msg.Label = "Test Message";
        msg.Formatter = new ActiveXMessageFormatter();

        MessageQueue queue = new MessageQueue("FormatName:DIRECT=OS:machine2\\Private$\\recievingQueue");

        queue.Send(msg);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM