在 NServiceBus 中,当消息传入而没有匹配的传奇时,我该如何处理?

发布于 2024-12-03 01:02:42 字数 151 浏览 3 评论 0原文

如果我有一个由两种消息类型组成的传奇,比如由 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 技术交流群。

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

发布评论

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

评论(2

难如初 2024-12-10 01:02:42

所以我想通了,我只需要为消息类型实现 IFindSagas

public class MySagaFinder : IFindSagas<MySagaData>.Using<Message2>
{
    public ISagaPersister Persister { get; set; }
    public IBus Bus { get; set; }

    public MySagaFinder FindBy(Message2 message)
    {
        var data = Persister.Get<MySagaData>("MessageIdProperty", message.MessageIdProperty);
        if (data == null)
        {
            Bus.Return(0);
        }
        return data;
    }
}

我不知道这是否是正确的方法,但它有效!

So I figured it out, I just needed to implement IFindSagas for the message type:

public class MySagaFinder : IFindSagas<MySagaData>.Using<Message2>
{
    public ISagaPersister Persister { get; set; }
    public IBus Bus { get; set; }

    public MySagaFinder FindBy(Message2 message)
    {
        var data = Persister.Get<MySagaData>("MessageIdProperty", message.MessageIdProperty);
        if (data == null)
        {
            Bus.Return(0);
        }
        return data;
    }
}

I don't know if this is the right way to do it, but it works!

岁月无声 2024-12-10 01:02:42

如果您的 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.

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