NServiceBus:事件、多重继承、每个事件多次调用处理程序

发布于 2024-09-12 04:55:26 字数 659 浏览 1 评论 0原文

我遇到了一些神秘的问题,每个事件多次调用处理程序,这似乎与通过接口继承建立的事件相关。

我们仅使用消息接口,并使用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 技术交流群。

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

发布评论

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

评论(1

独闯女儿国 2024-09-19 04:55:26

我知道答案很晚,但希望这对其他人有帮助。

当 IOperationOccured 和 ISpecificOperationOccured 的单独处理程序部署在同一端点中时,会发生这种情况。例如,

  • Endpoint1(引发 ISpecificOperationOccured)
  • Endpoint2(处理 IOperationOccured 和 ISpecificOperationOccured)

Endpoint1.Subscriptions 将包含以下项:

  • IOperationOccured ->端点2
  • ISpecificOperationOccured -> Endpoint2

这样,当发布 ISpecificOperationOccured 时,它将被发送到 Endpoint2 两次。推荐的方法是使用单独的端点来处理不同的消息类型。例如,

  • 端点 1(引发 ISpecificOperationOccured)
  • 端点 2(处理 IOperationOccured)
  • 端点 3(处理 ISpecificOperationOccured)

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 (Raises ISpecificOperationOccured)
  • Endpoint2 (Handles both IOperationOccured and ISpecificOperationOccured)

Endpoint1.Subscriptions will contain entries for:

  • IOperationOccured -> Endpoint2
  • ISpecificOperationOccured -> Endpoint2

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.

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