努力实施 IFindSagas
我有一个持续一天的传奇。
收到消息后,我想找到活动的传奇并在 Handle(message) 方法中执行操作。
我没有 ConfigureHowToFindSagas 方法,因为我想要当前的方法(如果有)。所有收到的消息都会影响一个传奇,直到收到超时消息。当前的传奇完成,并在收到新消息后创建新的传奇。但根据我所读到的内容,我需要实现 IFindSagas 才能做到这一点,可能还需要实现我自己的 Saga 持久化器。
我需要关于从哪里开始以及这是否是正确的方法的建议。代码示例会很有帮助,因为我对使用界面还比较陌生。
// fragment from Saga<PaymentSagaBase>
public void Run()
{
ScheduleBatchIDForSession = Guid.NewGuid();
// Message handlers aren't auto-subscribed in Saga scenarios so it needs to happen here.
Bus.Subscribe<PaymentRequested>();
Bus.Subscribe<PaymentCancelled>();
Logger.Info(string.Format("Creating new Saga.");
RequestUtcTimeout(DateTime.Now.AddHours(23), "End of batch");
}
I have a saga that runs for a day.
Upon receiving a message, I want to find the active saga and do things in the Handle(message) method.
I don't have a ConfigureHowToFindSagas method as I want the current one, if there is one. All messages received will impact on one saga until the timeout message is received. The current saga completes and a new one is created upon receiving a new message. But from what I've read, I need to implement IFindSagas in order to do this and possibly my own Saga persister.
I need advice on where to start and also if this is the right way to go. Code examples would be helpful as I'm still relatively new to using interfaces.
// fragment from Saga<PaymentSagaBase>
public void Run()
{
ScheduleBatchIDForSession = Guid.NewGuid();
// Message handlers aren't auto-subscribed in Saga scenarios so it needs to happen here.
Bus.Subscribe<PaymentRequested>();
Bus.Subscribe<PaymentCancelled>();
Logger.Info(string.Format("Creating new Saga.");
RequestUtcTimeout(DateTime.Now.AddHours(23), "End of batch");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我只是前几天回答了类似的问题。如果您有更复杂的逻辑来查找现有的 saga,则实现 IFindSagas 接口,否则重写 ConfigureHowToFindSaga 方法就足够了。您需要做的就是确保配置映射到启动传奇的消息。有点像这样:
HTH
I think I just answered a similar question the other day. If you have more complicated logic in order to find your existing saga, then implement IFindSagas interface, otherwise overriding the ConfigureHowToFindSaga method should be enough. All you need to do is make sure the configuration maps to the message that started the saga. Sort of like this:
HTH