将 NServiceBus 消息路由到特定客户端的最佳方法是什么? [英] What is the best way to route NServiceBus messages to specific clients?

查看:32
本文介绍了将 NServiceBus 消息路由到特定客户端的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个 ClientRequestMessage 消息,其中包含对特定 Client 的请求.Web 应用程序将生成这些请求,并且需要将它们发送到正确的 Client 进行处理.为此,我可以想到几个选项.

Let's say I have a ClientRequestMessage message that contains a request for a specific Client. A web application will generate these requests and they need to be sent to the correct Client for handling. I can think of a few options for this.

  1. 我可以有一个队列,所有消息都将发送到该队列,并且特定的客户端处理程序会检查一个属性(如 ClientId)来决定他们是否关心它.不过,这对我来说在很多层面上都是错误的.
  2. 我可以向所有客户端发布消息,他们可以在处理过程中决定是否关心它.不过,这似乎流量太大,浪费了每个客户的时间来处理他们一开始不应该关心的消息.
  3. 我可以拥有客户端特定的队列,这些消息也可以被路由.这个对我来说感觉最好,但我不确定如何去做.我想保持简单并避免客户端特定的消息类型,但我不确定如何告诉 NServiceBus客户端 A 将其发送到客户端 A 的队列,而客户端 B 将其发送到客户端 B 的队列".
  1. I could have a single queue that all messages go to and specific client handlers check a property (like ClientId) to decide whether they care about it. This feels wrong on many levels to me though.
  2. I could publish a message to all of the clients and they could decide whether or not they care about it during handling. This seems like too much traffic and wastes each client's time handling messages they shouldn't care about in the first place though.
  3. I could have client specific queues that these messages get routed too. This one feels the best to me, but I am unsure of how to do it. I'd like to keep it simple and avoid client specific message types, but I am not sure how to tell NServiceBus "for client A send it to client A's queue and for client B send it to client B's queue".

所以我的问题是,设置它的最佳(最有效?最容易管理?)方法是什么?我很确定我需要使用分销商,但不是肯定的,所以我想我会问.

So my question is, what is the best (most efficient? easiest to manage?) way to set this up? I am pretty sure I need to use the distributor, but not positive so thought I would ask.

额外问题:
假设每个客户端都有多个处理程序.我怎样才能确保只有其中一个处理给定的消息?我需要为每个客户指定一个分销商吗?

BONUS QUESTION:
Let's say each client has multiple handlers. How can I make sure only one of them handles a given message? Would I need a distributor per client?

推荐答案

您可以使用 MessageEndpointMappings 配置部分告诉 NSB 将消息放在哪里.您可以将特定消息类型或整个程序集映射到队列.如果您不想创建特定的消息类型并映射它们,那么我会推荐发布方法.从队列中删除消息的开销非常小.

You can tell NSB where to put messages by using the MessageEndpointMappings configuration section. You can map a specific message type or a whole assembly to a queue. If you don't want to create specific message types and map them, then I would recommend the publish approach. The overhead of removing a message from the queue is pretty minimal.

如果您的客户端"有许多 NSB 实例来接收消息,那么您将需要使用分发服务器.查看分布式发布/订阅文档.

If your "client" has many instances of NSB to pick up messages then you will need to use a Distributor. Check out the distributed Pub/Sub documentation.

这篇关于将 NServiceBus 消息路由到特定客户端的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆