Axon Replay TrackingEvent related to some “aggregateIdentifier” using Axon 4

眉间皱痕 提交于 2021-02-07 04:32:49

问题


We are using CQRS and Event Sourcing using Axon 4.

We have the following scenario.

Domain Book

  1. Action- Create new Book into DB using the Axon CRQS and event sourcing flow (Command - Aggregate - Event)
  2. Action- Update the already created Book into DB using the Axon CRQS and event sourcing flow (Command - Aggregate - Event)
  3. In the Axon event store this two commands explained above (createCommand and updateCommand) have the same "aggregateIdentifier" id, they are in the same Aggregate tree, because we are working on the same Aggregate root.
  4. In the Axon event store this commands have different "aggregateSequenceNumber", also this is normal and expected

At this point we are doing replay events by processingGroup, and this works fine, now we want to do more complex replay of the events

Question

How can we create resetTokens that will replay only the events with some "aggregateIdentifier" id (one Aggregate tree), this means we want to replay only the events related to some book (Aggregate tree) and not all books ?

Is this functionality supported by the Axon 4 ?


回答1:


You could create this feature with Axon if you'd want, but it requires some custom code using Axon Framework specifics.

Firstly though, this is not a replay as replays are described from an Event Processor level. Replaying an Event Processor will start reading the entirety of the Event Stream from a point in time based on the given token.

What you'd want is to replay and filter for a given aggregate identifier.

From the description in your comment, this feels like a sporadic query a user/service does against your application.

Upon handling this query, you will need to open an Event Stream, filter the events and then use the remaining stream to update the required query model.

From an implementation perspective, I would use a AnnotationEventHandlerAdapter. This class should be given an annotated event listener, which should be the Query Model you want to create ad-hoc and return.

Subsequently, the AnnotationEventHandlerAdapter#handle(EventMessage<?>) method should be called with the filtered event stream. Once you've reached the end of the stream, then you're query model is up to date.

So, to circle back to your question:

Is this functionality supported by the Axon 4 ?

The answer to this is yes, but it requires some handy work from your part.



来源:https://stackoverflow.com/questions/59199109/axon-replay-trackingevent-related-to-some-aggregateidentifier-using-axon-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!