Reputation: 356
(Originally logged on GitHub but thought I would move it here for anyone with the same question and to help the development team keep questions in the same place.)
I am not sure if this is my ignorance with the framework or an actual issue, please bear with me as I have been able to find very little documentation on Axon 4 with regard to event replaying.
Scenario:
@Component
@ProcessingGroup("projections")
public class AddEventHandler {
@EventHandler
public void on(AddEvent addEvent, ReplayStatus replayStatus){
}
@ResetHandler
public void onReset() { // will be called before replay starts
// do pre-reset logic, like clearing out the Projection table for a clean slate
// this does not get executed
}
}
@Configuration
public class AxonConfig {
@Autowired
private EventProcessingModule eventProcessingModule;
@Autowired
public void configureProcessors(EventProcessingConfiguration configuration) {
configuration
.eventProcessorByProcessingGroup("projections",
TrackingEventProcessor.class)
.ifPresent(trackingEventProcessor -> {
trackingEventProcessor.shutDown();
trackingEventProcessor.resetTokens();
trackingEventProcessor.start();
});
}
}
This was taken from Replaying Events Documentation
The ifPresent content is never executed when the application is started, thus the tokens are never reset. I can manually force the replaying of events by deleting the token. The configuration mentioned above is the only configuration I have changed, everything else is running off the AutoConfiguration.
Token Storage is Microsoft SQL Server and all the interaction I can see there seems fine (events are persisted, token ownership is updated when the application is stopped etc).
When inspecting the EventProcessingConfiguration at runtime, the eventProcessors property is empty as is the processingGroupAssignments property which leads me to believe that the ProcessingGroup annotations are processed after the Autowired configuration has run, thus the ifPresent will never execute the code defined above.
Version info: Spring Boot Starter: 2.1.2, Axon Starter: 4.0.3
Upvotes: 2
Views: 690
Reputation: 356
Complete answer here: https://github.com/AxonFramework/AxonFramework/issues/1006
Quoted answer:
Now to resolve the issue you're having - it seems that you want to reset some of your query models at start up of the application. You are however hitting a configuration order problem in this scenario, where the TrackingEventProcessor have not been started yet, whilst the configuration file you've created is already being called.
Note that we have plans to be more specific on the ordering when specific beans are created (potentially with Spring application events if you'd ask me) - we are however no there yet, so please bear with us until this rework has been performed.
For now, the simplest approach you can take, is have a dedicated replay service. You'd than wire this ResetService/ReplayService with the EventProcessingConfiguration and have it contain a void resetProjectors() method. I'd suggest calling this method at a point in time where you're certain the application has been completely wired up (for example by handling some of the Spring application events).
Thanks again to the Axon development team.
Upvotes: 1