使用 IHandleMessages 的一些困惑

发布于 2024-10-31 00:56:12 字数 797 浏览 0 评论 0原文

我有一个订阅者订阅了多个不同的发布者。所有这些发布者都会发布其接口派生自基本接口的消息。该基本消息包含所有消息都需要的一些公共属性,并且是一个标记。

public interface IBaseMessage : IMessage
{}

public inteface IPublisher1Message : IBaseMessage
{}

public inteface IPublisher2Message : IBaseMessage
{}

在订阅者中,我创建了一个订阅系统中所有发布者的类。

public BaseMessageHandler : IHandleMessages<IBaseMessage>
{
  public void Handle(IBaseMessage message) {}
}

我希望它能够处理来自所有发布者的消息,但我看到它最多会触发一个发布者,具体取决于我如何进行消息端点映射。

<MessageEndpointMappings>
 <add Messages="Messages.IPublisher1Messages,Messages" Endpoint="Publisher1" />
  <add Messages="Messages.IPublisher2Messages,Messages" Endpoint="Publisher2" />
</MessageEndpointMappings>

有没有一种方法可以在一个处理程序中处理来自不同发布者的消息?

I have a subscriber that subscribes to multiple different publishers. All of these publishers post a message whose interface derives from a base interfaces. This base message contains some common attributes that all the messages require and is a marker.

public interface IBaseMessage : IMessage
{}

public inteface IPublisher1Message : IBaseMessage
{}

public inteface IPublisher2Message : IBaseMessage
{}

In the subscriber I have created a class that subscribes to all publishers in the system.

public BaseMessageHandler : IHandleMessages<IBaseMessage>
{
  public void Handle(IBaseMessage message) {}
}

I would like this to Handle the message from all publishers, but I have seen it fire for at most one publisher depending on how I do my message endpoint mappings.

<MessageEndpointMappings>
 <add Messages="Messages.IPublisher1Messages,Messages" Endpoint="Publisher1" />
  <add Messages="Messages.IPublisher2Messages,Messages" Endpoint="Publisher2" />
</MessageEndpointMappings>

Is there a way to handle messages from different publishers in one Handler?

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

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

发布评论

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

评论(1

夜空下最亮的亮点 2024-11-07 00:56:12

您是否依赖自动订阅这一功能?

因为我想我记得曾经遇到过与您类似的麻烦 - 据我所知,解决方案是手动订阅每条消息。

您仍然可以依赖多态消息调度,它只是多态自动订阅似乎不起作用。

Are you relying on auto-subscribe for this one?

Because I think I can recall having had some kind of trouble similar to yours - as I remember it, the solution was to manually subscribe to each message.

You can still rely on polymorphic message dispatch, it's just polymorphic auto-subscription that seems not to work.

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