NServiceBus - 处理同一消息的多个端点

NServiceBus - Multiple endpoints processing the same message

我有多个端点(在不同的服务器上,来自不同的公司)指向同一个 queue(我正在使用 "OverrideLocalAddress" 方法)。当我为此 queue 发送消息时,我添加了带有公司 ID 的 header。

我想要正确的端点来选择此消息。我正在使用 Pipeline 过滤我收到的消息(按 header 中的公司 ID),但只有第一个(随机)端点收到消息。

有没有办法让每个端点都选择一条消息?有没有更好的方法将消息发送到特定端点?

您正在使用 Competing Consumer 模式,这是一个很棒的模式!

https://www.enterpriseintegrationpatterns.com/patterns/messaging/CompetingConsumers.html https://docs.microsoft.com/en-us/azure/architecture/patterns/competing-consumers

我假设您不需要消息到达特定端点,您需要在特定数据库中更新数据。换句话说,您需要多租户,这使您能够使用相同的代码库为不同的客户提供服务,同时最大限度地减少他们对彼此的影响。

我们最近写了一篇关于 NServiceBus 中一些新功能的博文,以更好地实现这一点:https://particular.net/blog/multi-tenancy-support-in-sql-persistence

您应该能够提供自定义代码和自定义连接字符串(针对特定客户数据库)以启用多租户。也就是说,取决于您使用的持久性。我们有 documentation for SQL Server and other persisters and also samples that explain how to inject tenant-aware components into message handlers or propagate tenant information to downstream endpoints.

希望对您有所帮助。

更新 我不确定这是最好的解决方案,可能还有其他解决方案,但您可以使用 SendOptions 路由到特定的逻辑端点,but also to a specific instance of an endpoint.