使用WCF直接发送到MSMQ队列

发布于 2024-10-08 20:12:51 字数 225 浏览 2 评论 0原文

我有一个 Windows 服务,可以从各种 MSMQ 中获取消息。该服务从队列中获取消息,然后根据消息来自的队列执行特定的工作流。是否可以将 WCF 服务配置为接受来自端点的消息并将其放入队列中?我希望该服务具有多个端点,并且根据接收消息的端点,消息将被放置在不同的队列中。我已经看到了有关 netMsmqBinding 的内容,但到目前为止我还无法确定这是否适合我正在考虑的用途。

感谢任何帮助,

迈克

I have a windows service that picks up messages from various MSMQs. The service picks up the messages from the queues, and then executes a specific workflow based on the queue the message came in from. Is it possible to configure a WCF service to accept a message from an endpoint and place it in a queue? I would like for the service to have multiple endpoints, and depending on which endpoint received the message, the message would be placed in a different queue. I have seen things about netMsmqBinding but so far I haven't been able to determine if this is meant for the use I am thinking about.

Any help is appreciated,

Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

愿得七秒忆 2024-10-15 20:12:51

我是否正确理解这一点 - 您希望

  • 使用多个端点将 WCF 服务暴露给外界,
  • 具体取决于消息进入 WCF 服务的端点,它应该将这些消息放入单独的 MSMQ 队列中?

您绝对可以拥有一个 WCF 服务,它将向外部公开任意数量的端点,并将传入消息放入 MSMQ 队列中。我只是不确定您是否能够在 WCF 服务方法内部知道请求来自哪个端点......通常,WCF 服务类不知道请求来自哪里(并且通常不需要知道...)。

我看到了一些方法:

  • 有多个服务,每个端点(类型)一个;他们可以共享所有代码和所有内容,但如果将其分成单独的服务类,那么每个服务类本质上都会知道它服务的端点,因此可以知道将信息放入哪个 MSMQ 队列

  • 找到一种方法来发送一些标头信息和消息,以某种方式告诉您将消息放在哪里

  • < p>在 WCF 4.0 中,您也许可以使用新的 WCF 路由服务做一些事情......但是不太确定它是如何工作的 - 因为它还需要某种“提示”来知道它是哪个端点调用以及如何

Am I getting this correctly - you want to have

  • a WCF service exposed to the outside world using multiple endpoints
  • depending on which endpoint the message comes into the WCF service, it should put those messages into separate MSMQ queues?

You can definitely have a WCF service that will expose any number of endpoints to the outside and that would drop incoming messages into an MSMQ queue. I'm just not sure whether you'll be able inside the WCF service method to know which endpoint the request came in on..... typically, the WCF service class doesn't know anything about where the request came from (and typically doesn't need to know...).

I see a few approaches to this:

  • have multiple services, one for each (type of) endpoint; they can share all their code and everything, but if you separate this into separate service classes, then each service class would inherently know what endpoint it serves, and thus could know what MSMQ queue to put the info into

  • find a way to send some header information along with the message that somehow tells you where to put the messages

  • in WCF 4.0, you might be able to do something with the new WCF Routing Service.... not quite sure how that would work, however - since it would also require some kind of "hint" to know which endpoint it was called on and how to route the incoming message

晚雾 2024-10-15 20:12:51

我能够解决此问题的方法是创建一个自定义 ServiceHost 类,我可以将配置名称传递给该类。这是使用服务实现类型名称来查找配置的默认实现的替代方案。这允许我在同一台机器上运行相同实现的多个实例。除此之外,在自定义服务类中,我添加了一个自定义 MessageInspector,它将自身附加到每个端点以侦听消息。然后,我使用 IDispatchMessageInspector.AfterReceiveRequest() 方法获取传入消息,然后将其放入我在配置中定义的队列中。有点复杂,但它非常适合我们的场景。

The way I was able to go about this was by creating a custom ServiceHost class that I could pass a configuration name to. This is an alternative to the default implementation that uses the Service Implementation type name to locate the configuration. This allowed me to run multiple instances of the same implementation on the same machine. In addition to that, inside the custom service class I added a custom MessageInspector that would attach itself to every endpoint to listen for messages. I then use the IDispatchMessageInspector.AfterReceiveRequest() method to take the incoming message and then place it into a queue that I define inside my configuration. A little complicated, but it works perfectly for our scenario.

只怪假的太真实 2024-10-15 20:12:51

net.msmq 绑定允许 WCF 客户端直接写入 MSMQ 队列,即使队列读取 WCF 服务不活动 — 它甚至不必存在。 net.msmq 绑定还允许从队列中自动读取。不使用 MessageQueue 写入队列或从队列中读取。

net.msmq bindings allow a WCF client to write directly to an MSMQ queue, even if the queue-reading WCF service is not live -- it doesn't even have to exist. net.msmq bindings also allows automagic reading from queues. No use of MessageQueue to write to, or read from, a queue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文