且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

J Olivers活动商店-Saga帮助

更新时间:2022-06-26 06:17:42


  1. 命令放在要在总线上发送的标头中。 EventStore与事件的存储有关,因此导致传奇转换的事件得以保留。稍后,当从事件流中加载saga时,事件将传递到saga的transition方法,以使其变为当前状态。

  1. The commands are put in the headers to be sent on the bus. The EventStore is concerned with the storage of events so the events that caused saga transitions are persisted. Later, when the saga is loaded from the event stream, the events will be passed to the saga's transition method to bring it to the current state.

过渡该方法在saga实现中具有双重目的。调用转换来处理传入的消息并从持久性中加载传奇。在SagaEventStoreRepository.BuildSaga中,在建立当前状态后,在saga上调用ClearUncomittedEvents和ClearUndispatchedMessages,从而避免了重复的事件和命令处理。

The transition method serves a dual purpose in the saga implementation. Transition is called to handle incoming messages and to load the saga from peristence. In SagaEventStoreRepository.BuildSaga ClearUncomittedEvents and ClearUndispatchedMessages are called on the saga after the current state is built up thus avoiding duplicate event and command processing.

我个人没有做到了这一点,但我将为sagas使用单独的EventStore实例。这将允许使用单独的IPublishMessages实现从事件标头中获取命令并将其发送。

I haven't personally done this but I would use a separate EventStore instance for my sagas. This would allow for the usage of a separate IPublishMessages implementation to take the commands from the event headers and send them.