Replay of one aggregate

Hello,

Please can you give me advice how to replay only one aggregate (not aggregate type) with given id on the fly?

Let’s say something wrong happened in the end while ObjectTypeEventListener was creating my object type (table + columns). Now I’d like to use this ObjectTypeEventListener (which is subscribing by default and spring bean) to rebuild that one object.

So I guess I must create new instance of this ObjectEventListener as TrackingEventProcessor and assign those events which I’m interested in.
Then remove data from projections (delete rows from object_type, object_type_columns with objectTypeId).
Then start the projection.

basically it should be action to rebuild object_type.

is there a simple way for doing this?

Any example would be greatly appreciated

thanks

Lukas

So for now I’ve ended up with this… please tell me your opinion.

private void rebuildObjectType(String objectTypeId) {
   EventHandlerInvoker eventHandlerInvoker =
         new SimpleEventHandlerInvoker(
               new ObjectTypeTableCreatorListener(liquibaseUtils, attributeEntityQueryRepository));

   DomainEventStream eventStream = eventBus.readEvents(objectTypeId);
   eventStream
         .asStream()
         .forEach(event ->
         {
            try {
               eventHandlerInvoker.handle(event);
            } catch (Exception e) {
               throw new RuntimeException(String.format("Unable to rebuild object type [%s] because of error", objectTypeId), e);
            }
         });
}

Hi Lukáš,

I’ve done similar things couple of months ago.
My scenario was that one of my Event Listeners was interested in event stream for a specific aggregate once a certain ‘association’ event came along.
From that point on, I knew I also wanted the previous events for that aggregate.
I solved it by replaying the events for that newly associated aggregate against an AnnotationEventListenerAdapter, which implements the interface EventListener.

So, the only difference I had with your approach, is that I used a EventListener, and you used an EventHandlerInvoker.
To be fair, not sure which is better.
I do know however that the AnnotationEventListenerAdapter also has the option to set ParameterResolvers (for example to resolve the event timestamp by using the @Timestamp annotation on a parameter of type Instant ).

In short, I do not think this is all to wrong.
Other opinions are still appreciated of course, also on my approach.

Hope this helps!

Cheers,

Steven

Hi Steven,
Thanks for suggestion. I will keep EventHandlerInvoker it has also constructor which accepts ParameterResovler.
So if somebody has other approach it will be welcome.

Thanks

Lukas