使用 IHandleMessages 的一些困惑
我有一个订阅者订阅了多个不同的发布者。所有这些发布者都会发布其接口派生自基本接口的消息。该基本消息包含所有消息都需要的一些公共属性,并且是一个标记。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否依赖自动订阅这一功能?
因为我想我记得曾经遇到过与您类似的麻烦 - 据我所知,解决方案是手动订阅每条消息。
您仍然可以依赖多态消息调度,它只是多态自动订阅似乎不起作用。
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.