在 NServiceBus 中,当消息传入而没有匹配的传奇时,我该如何处理?
如果我有一个由两种消息类型组成的传奇,比如由 message1 开始并由 message2 完成,那么如果 message2 进入而 message1 不存在,我可以返回回调吗?我知道它会将其转储到错误队列中,但我希望能够向发送客户端返回一个状态,表明由于第一条消息不存在而存在错误状态。
If I have a saga that consists of two message types, say started by message1 and completed by message2, can I return a callback if a message2 comes in without a message1 already existing? I know it will dump it in the error queue, but I want to be able to return a status to the sending client to say there is an error state due to the first message not being there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所以我想通了,我只需要为消息类型实现
IFindSagas
:我不知道这是否是正确的方法,但它有效!
So I figured it out, I just needed to implement
IFindSagas
for the message type:I don't know if this is the right way to do it, but it works!
如果您的 saga 可以接收两条消息,但可以按任意顺序接收消息,请确保两条消息都可以启动 saga。然后通过在传奇本身中设置某种状态来验证两条消息是否已到达。如果两条消息均已到达,则将其标记为完成。
默认的 NServicebBus 行为是忽略任何没有相应传奇的消息。例如,这是因为您可以设置超时。如果 24 小时内没有任何反应,saga 可以向自身发送一条 Timeout 消息。但是,如果确实发生了某些事情并且您将传奇标记为已完成,那么超时消息会发生什么情况?因此 NServiceBus 会忽略它。
If you have a saga that can receive two messages, but messages can be received in any order, make sure the saga can be started by both messages. Then verify if both message have arrived by setting some state in the saga itself. If both messages have arrived, mark it as complete.
Default NServicebBus behavior is to ignore any message that has no corresponding saga. This is because you can set a timeout, for example. If nothing happens within 24 hours, the saga can send a Timeout message to itself. But if something did happen and you marked your saga as being completed, what should happen to the Timeout message? Therefor NServiceBus ignores it.