NServiceBus:事件、多重继承、每个事件多次调用处理程序
我遇到了一些神秘的问题,每个事件多次调用处理程序,这似乎与通过接口继承建立的事件相关。
我们仅使用消息接口,并使用NServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper().CreateInstance()
来创建要放在总线上的实例。
我们的接口:
IOperationOccured - 包含基本操作信息,该事件的订阅者以相当通用的方式对事物进行操作。该事件永远不会直接引发。
ISpecificOperationOccured
- 继承IOperationOccured
。包含更具体的信息。由于事件更加具体,因此该事件的订阅者能够做更具体的事情。
问题是,当引发 ISpecificOperationOccured
时,IOperationOccured
的处理程序被调用,ISpecificOperationOccured
的处理程序被调用,然后消息似乎得到再次处理,再次调用处理程序。
我有什么误解吗?我希望每个事件调用一次 IOperationOccured 的处理程序,并且每个事件调用一次 ISpecificOperationOccured 的处理程序。
I'm have some mysterious problems with handlers being called more than once per event which appears to be correlated with events built up via interface inheritance.
We are using only interfaces for our messages and usingNServiceBus.MessageInterfaces.MessageMapper.Reflection.MessageMapper().CreateInstance()
to create instances to put on the bus.
Our interfaces:
IOperationOccured
- Contains basic operation information, subscribers to this event act on things in a fairly generic way. This event is never raised directly.
ISpecificOperationOccured
- Inherits IOperationOccured
. Contains more specific information. Subscribers to this event are able to do more specific things since the event is more specific.
The problem is that when ISpecificOperationOccured
is raised, the handlers for IOperationOccured
are called, the handlers for ISpecificOperationOccured
are called and then the message appears to get processed again, calling the handlers again.
What am I misunderstanding? I'd expect the handlers for IOperationOccured
to get called once per event and the handlers for ISpecificOperationOccured
to get called once per event.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道答案很晚,但希望这对其他人有帮助。
当 IOperationOccured 和 ISpecificOperationOccured 的单独处理程序部署在同一端点中时,会发生这种情况。例如,
Endpoint1.Subscriptions 将包含以下项:
这样,当发布 ISpecificOperationOccured 时,它将被发送到 Endpoint2 两次。推荐的方法是使用单独的端点来处理不同的消息类型。例如,
Late answer I know but hopefully this will help others.
This happens when your separate handlers for IOperationOccured and ISpecificOperationOccured are deployed in the same endpoint. e.g.
Endpoint1.Subscriptions will contain entries for:
So that when ISpecificOperationOccured is published it will get sent to Endpoint2 twice. The recommended approach is to have separate endpoints for the handling of different message types. e.g.