J Olivers活动商店-Saga帮助 [英] J Olivers Event Store - Saga Help

查看:80
本文介绍了J Olivers活动商店-Saga帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jonathan Olivers EventStore和CommonDomain围绕Saga的想法。我了解聚合如何与CommonDomain / EventStore一起使用,但是我一直在掌握Saga的用法。我已经阅读了Jonathan的Saga和Event Sourcing Part I& II,但在实际实现中仍然失败

I am trying to wrap my head around Saga's using Jonathan Olivers EventStore and CommonDomain. I understand how Aggregates are working with the CommonDomain/EventStore but I am stuck on grasping Saga usage. I have read both of Jonathan's Saga's with Event Sourcing Part I & II but sill lost in actual implementation

1)更多观察,当坚持传奇时,EventStore使用标头来坚持传奇和需要发送的命令并且有效载荷似乎存储了触发Saga唤醒的事件。奇怪的原因。我们永远都不想存储单个命令,而不是将所有命令都存储在标题中吗?

1) More of observation, when persisting the saga the EventStore is utilizing the Headers to persist the Saga and Commands that need to be sent out and it looks like the Payload is storing the Event that triggered the Saga to "wake up". Wondering reasons for this. Would we never want to store individual commands vs having them all in the header?

1)似乎触发Saga的事件自转换后被重播了多次SagaBase中的方法始终会将事件重新添加到未提交的集合中。 (不同于具有内部Apply方法与Public Domain方法的AR)。也许我没有正确使用Transition方法

1) It seems like the Event that triggered the Saga gets replayed multiple times since the "Transition" method in SagaBase always re-adds the event to uncommitted collection. (Unlike ARs that have an internal Apply method vs public Domain method). Maybe I am not using the Transition method properly

2)通常,与EventStore一起使用的总线将发布事件(我实现了IPublishMessages)。如果我需要我的传奇来发布命令,似乎没有发送选项。我是否需要解析标题以亲自获取命令?

2) Typically the bus that you use with the EventStore will publish Events (I implemented IPublishMessages). If I need my Saga to publish a command there does not seem to be a Send option. Do I need to parse the Headers to grab the commands myself?

我认为我不正确地使用CommonDomain / EventStore,因为使用Aggregates很容易,但是Saga对我来说似乎不完整。我假设它是因为我没有正确执行。对于CQR​​S还是很新的。有人知道佐贺县使用J Olivers公共域/事件存储的有效示例吗?我认为这样可以使事情大为改善。

I am thinking I am using the CommonDomain / EventStore incorrectly as working with Aggregates was easy but Saga's seem "incomplete" to me. I am assuming its because I am not doing it correctly. Still very new to CQRS. Does anyone have a working example of Saga's using J Olivers Common Domain / Event Store? I think that would clear things up considerably.


我想我已经弄清楚了,但还是需要一些投入。 Saga确实不应该发布活动。他们发出命令。因此,在EventStore(IPublishMessages)的发布方面,我应该首先检查消息的类型(AggregateType与SagaType)。对于AggregateTypes,我可以发布事件,但对于SagaTypes,仅发布命令(位于Header中)。这样就消除了触发事件的创建的同一事件(例如OrderSubmittedEvent),该事件会在持久存储该事件时触发该事件而不再发布。

I think I figured it out but would like some input. Saga's really should not be publishing events. They send out commands. Thus on the publish side of things for the EventStore (IPublishMessages) I should first be checking the type of message (AggregateType vs SagaType) For AggregateTypes I can publish Events but for SagaTypes only publish the commands (found in Header). This eliminates the same event (say OrderSubmittedEvent) that triggers the creation of the Saga to not publish it again when persisting the saga.

推荐答案


  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.

这篇关于J Olivers活动商店-Saga帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆