具有事件溯源的基于时间的 Sagas
假设我想要一个由某个事件创建的传奇,然后等待几个小时,如果没有任何反应,则发送一些命令。
现在,如果这个 Saga 全部在内存中,并且我必须重新启动应用程序/服务器,那么该 Saga 将被卸载并且再也不会出现,对吧?
系统恢复在线后,我是否会使用事件源来加快此 Saga 的速度?
如果是这样,我几乎需要一个单独的事件存储,其中包含可以在系统启动时重播的“活动传奇”,以使我的传奇加快速度。到目前为止,这对我来说似乎不错,但是我将如何实现超时呢?
我需要某种方法在重播时“伪造”超时,考虑到可能有多个后续超时,具体取决于传奇中发生的事件。
Let's say I wanted to have a saga that get's created by some event, then sits and wait for a few hours, and if nothing happens, sends off some command.
Now, if this Saga was all in-memory and I had to restart the app/server, the saga would be unloaded and never seen again, right?
Would I use Event Sourcing to bring this Saga up to speed once the system is back online?
If so, I would need pretty much a separate Event Store with "active sagas" that can be replayed at system startup, to get my Sagas up to speed. So far it seems good to me, but how would I implement the timeout?
I would need some way of "faking" the timeouts at replay, taking into account there may be several, subsequent timeouts depending on the events going into the saga.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现此功能的最佳方法是使用另一个能够在某个时间点向您返回消息的端点。例如,您的传奇可能会向这个“超时管理器”发送一条消息,并说在 1 小时或 1 天甚至 1 年内叫醒我。届时该消息将返回给您。理想情况下,此消息应具有导致操作发生的业务含义。
也许最好的例子就是客户注册,如果客户在注册后 7 天内没有确认他们的帐户,您将通过电子邮件通知他们。 “超时消息”实际上是:RemindUserToConfirmAccountMessage。当 7 天后 saga 收到此消息时,saga 将根据其当前状态确定是否需要处理该消息并发送客户电子邮件。但如果用户已经确认了他/她的帐户,则可以丢弃该消息而不采取任何操作。
The best way to achieve this capability is with another endpoint that is capable of returning a message back to you at a certain point in time. For example, your saga may dispatch a message to this "timeout manager" and say wake me in 1 hour or 1 day or even 1 year. The message would then be returned to you at that time. Ideally this message would have business meaning that would cause an action to occur.
Perhaps the best example of this is something like customer signup where, if the customer hasn't confirmed their account within 7 days from signup, you'd notify them via email. The "timeout message" would effectively be: RemindUserToConfirmAccountMessage. When this message is received back by the saga after 7 days, the saga would determine based upon its current state, if that message needs to be handled and a customer email needs to be sent. But if the user has already confirm his/her account, the message can be discarded with no action taken.