NServicebus 和消息处理程序顺序
抱歉我不清楚。事实上,处理程序之间没有任何依赖关系,其中一些处理程序只是处理相同类型的消息。例如,在我们的系统中,我们处理发票,当发票到达系统时,会发生非常简单的情况:“InvoiceArrived”消息被发送到 nservicebus,并且应该发生两件事,有关发票的信息应发送到外部系统,并且电子邮件应发送给负责处理发票的人员(根据发票上的信息,不同的人)。这两件事彼此没有依赖性,但导出到外部系统非常重要,而电子邮件则不那么重要。
发生的情况是,发送电子邮件的处理程序首先运行,然后崩溃(由于配置错误),重试了五次,但每次都崩溃,并且电子邮件和导出到外部系统都没有发生。修复配置很容易,但它向我们展示了设计中的缺陷。
我现在意识到我们必须重新考虑设计,因为指定处理程序运行的顺序不会解决任何问题,因为相反的情况也是不可取的,它首先运行导出处理程序,然后在电子邮件处理程序中崩溃,导致五个重试并成功导出五次(但没有成功的电子邮件)。我想我们必须为每个处理程序发送一种消息类型...
原始消息:
我们正在使用 NServiceBus 为许多事件设置处理程序,每个处理程序向总线发送一个唯一的消息类型(目前有 6 个,但数量正在增长) )。其中一些事件(目前有 2 个)具有多个处理程序,我们希望它们针对每种消息类型以特定顺序执行。
我们有自己的主机,我知道您可以将顺序指定为: NServiceBus.Configure.With() ... .UnicastBus() .LoadMessageHandlers(First.Then().AndThen().AndThen() //etc)
假设我们有消息处理程序 H1_1, H1_2 (都处理类型 1 的消息,H1_1 在 H1_2 之前执行)相应地 H2_1, H2_2 (处理类型 2) 的消息和 H3 - H6 (唯一处理类型 3 - 6 的消息)
当然,我们可以通过以下方式管理它指定所有处理程序
.LoadMessageHandlers(First<H1_1>.Then<H1_1>().Then<H2_1>() //etc)
,但这意味着每次我们添加一个新处理程序时,我们都必须添加到此配置中,
是否可以这样写:
.LoadMessageHandlers(First<H1_1>.Then<H2_1>()) //and all the other handlers are run there after?
这当然会更好,但 H1_1 和 H2_1 仍然彼此没有任何关系,并且不会无论如何运行同一条消息。是否无法指定每个消息类型,即类型 1 First
和类型 2 First
对于所有其他类型,由于只有一个处理程序,因此不需要指定?
预先非常感谢您 - 任何帮助将不胜感激!
I'm sorry I was unclear. In fact there are not any dependencies between the handlers, some of them just handle the same type of message. For instance in our system we handle invoices, very simplified this happens when an invoice arrives to the system: an "InvoiceArrived" message is sent to the nservicebus and two things should happen, information about the invoice should be sent to an external system and an email should be sent to the person who is to handle the invoice (different person depending on the information on the invoice). These two things has no dependency on each other but the export to the external system is very important whereas the email is not as important.
What happened was that the handler sending email was run first and it crached (due to bad configuration), it was retried five times but crached each time and neither email nor export to external system took place. Fixing the configuration was easy but it showed us a flaw in our design.
I reallize now that we have to rethink the design because specifying the order in which the handlers are run would not solve anything as the opposite situation is also not desirable, that it runs the exporting handler first and then craches in the emailing handler resulting in five retries and five successful exports (but no successful email). I guess we will have to send one message type for each handler...
Original message:
We are using NServiceBus to set up handlers for a number of events, each sending a unique message type to the bus (currently 6 but the number is growing). Some of these events (2 at the moment) have more than one handler and we want them to be executed in a specific order for each of the message types.
We have our own host and I know you can specify the order as:
NServiceBus.Configure.With()
...
.UnicastBus()
.LoadMessageHandlers(First.Then().AndThen().AndThen() //etc)
Lets say we have message handlers H1_1, H1_2 (both handling messages of type 1, H1_1 to be executed before H1_2) correspondingly H2_1, H2_2 (handling messages of type 2) and H3 - H6 (the only ones to handle messages of type 3 - 6)
Of course we can manage this by specifying all handlers
.LoadMessageHandlers(First<H1_1>.Then<H1_1>().Then<H2_1>() //etc)
but this means that every time we add a new handler we have to add to this configuration,
is it possible to write
.LoadMessageHandlers(First<H1_1>.Then<H2_1>()) //and all the other handlers are run there after?
That would of course be better but still, H1_1 and H2_1 has nothing with each other to do and will not be run on the same message any way. Is there no way to specify per message type, i.e. for type 1 First<H1_1>.Then<H1_2>()
and for type 2 First<H2_1>.Then<H2_2>()
and for all other types no specification is necessary since there is only one handler?
Thank you very much in advance - any help will be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正是出于这些原因,在 3.0 版本中,我们将支持 ISpecifyMessageHandlerOrdering 的多种实现。
In version 3.0 we're going to support multiple implementations of ISpecifyMessageHandlerOrdering for exactly these reasons.