NServiceBus 端点可以订阅同一消息的多个发布者吗?

发布于 2024-12-29 06:52:33 字数 757 浏览 2 评论 0原文

我正在开发一个系统来支持从各种硬件类型接收状态信息。每个硬件都报告相同的状态信息(纬度、经度),但每种硬件类型使用独特的协议来报告此信息。因此,我有多个服务,每种设备类型一个,用于侦听和解析该设备的协议。我希望每个服务都使用通用消息发布状态信息:

public interface IPositionMessage : IMessage
{
   string UnitName { get; set; }
   double Latitude { get; set; }
   double Longitude { get; set; }
}

我在设置第一个服务时没有遇到任何问题,但现在我正在设置第二个服务,我发现我的订阅者无法订阅来自多个发布者的同一条消息。

在类似的关于 NServiceBus yahoo 群组的问题中,推荐的解决方案是将公共消息转换为命令并使用 Bus.Send 而不是 Bus.Publish。我觉得在这种情况下这没有意义,因为真正发生的是一个事件(该单位已经到达一个位置并正在报告新位置)。如果我要将其转换为命令,我需要提前知道该事件的所有潜在订阅者,但我不需要。另一种可能的解决方案是创建一个聚合/重新发布器,每个服务都将 Bus.Send 发送到该聚合/重新发布器,然后从单个发布者重新发布消息。这似乎是一个不必要的瓶颈。

有没有什么方法可以让订阅者从多个发布者那里订阅同一条消息?

I am developing a system to support receipt of status information from a variety of hardware types. Each piece of hardware is reporting the same status information (Latitude, Longitude), but each hardware type uses a unique protocol for reporting this information. For this reason I have multiple services, one for each device type, that listen for and parse the protocol of that device. I would like for each of these services to publish the status information using a common message:

public interface IPositionMessage : IMessage
{
   string UnitName { get; set; }
   double Latitude { get; set; }
   double Longitude { get; set; }
}

I had no trouble setting up my first service, but now that I am setting up my second service I'm finding that my subscribers are unable to subscribe to the same message from multiple publishers.

In a similar question on the NServiceBus yahoo group, the recommended solution is to convert the common message to a command and use Bus.Send rather than Bus.Publish. I don't feel that makes sense in this scenario since what is really happening is an event (the unit has already arrived at a position and is reporting the new position). If I were to convert this to a command I would need to know in advance all of the potential subscribers to this event, which I don't. Another possible solution would be to create an aggregation/re-publisher that each service would Bus.Send to, and then the message would be republished from a single publisher. This seems like an unnecessary bottleneck.

Is there any method to allow for subscribers to subscribe to the same message from multiple publishers?

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

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

发布评论

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

评论(2

度的依靠╰つ 2025-01-05 06:52:33

这是 Udi 试图让您很难逃脱的 SOA“成功坑”之一。

基本的二元性是这样的:

  • 命令应该由许多客户端发送并由单一权威源接收。
  • 活动应由单一权威来源发布并被许多客户接收。

但这个单一的权威来源是逻辑上的权威来源。重要的一点是,如果我对所有 IPositionMessage 数据感兴趣,则应该只有一个逻辑点 (queuename@servername),我可以在其中发送订阅请求。

这并不意味着同一逻辑服务中的多个物理处理器不能全部发布相同的事件类型,只要它们发布的内容是权威的。

关键是所有物理处理器必须共享相同的订阅存储。事实上,您可能希望让一个物理端点仅处理订阅请求,而不进行任何处理。它只是接收订阅请求(QueueX@ServerY 对 IPositionMessage 感兴趣)并更新订阅存储。

然后,绑定到同一订阅存储的每个处理器都会发布 IPositionMessage,并会发现 QueueX@ServerY 感兴趣,并将事件的副本发送到该位置。

在运行 NServiceBus.Lite 配置文件的开发环境中,这将有点难以接受,因为默认情况下订阅存储位于内存中,因此显然它不会被共享,并且不会出现正确运行的情况,因此请做好准备为此。

This is one of those SOA "pit of success" things that Udi tries to make it very hard for you to escape from.

The basic duality is this:

  • Commands should be sent by many clients and received by a single authoritative source.
  • Events should be published by a single authoritative source and received by many clients.

But this single authoritative source is a LOGICAL authoritative source. The important point is that if I am interested in all IPositionMessage data, there should be only one logical point (queuename@servername) where I send my subscription requests.

That doesn't mean that multiple physical processors within the same logical service can't all publish the same event type, as long as what they publish is authoritative.

The key is that all your physical processors must share the same subscription storage. In fact, you may want to have one physical endpoint handle only the subscription requests and do no processing at all. It just receives subscription requests (QueueX@ServerY is interested in IPositionMessage) and updates the subscription storage.

Then, each processor, tied to the same subscription storage, goes to publish IPositionMessage and will find that QueueX@ServerY is interested, and send a copy of the event to that location.

This will be a little bit hard to swallow in a dev environment with the NServiceBus.Lite profile running, because the subscription storage is in-memory by default, so obviously it will not be shared and will not appear to run correctly, so be ready for that.

北城半夏 2025-01-05 06:52:33

虽然可以订阅多个发布者(这可以在 中配置),但我同意用户组的观点,因为这应该成为逻辑发送而不是发布。

我不太清楚为什么我会这么想。

While it's possible to subscribe to more than one publisher (this can be configured in the <unicastBusConifg />), I agree with the user group in that this should then become a logical send rather than a publish.

I don't quite know why I think this though.

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