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
Thanks and apologies if this is my ignorance and the behaviour is as expected. If more information is required please let me know.
Hi @RabidDog, I think I can help you with this issue. I'd however first like to point out a household item.
For questions regarding usage of the framework, we typically refer to the User Group or StackOverflow with the tag axon. That way, we keep the issue tracker for framework issues. I could however understand if you weren't certain whether this is a bug or a question, hence why I'll answer it regardless. :-)
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).
I hope this gives you some insights @RabidDog and that it resolves the problem you're encountering!
And, the note you've placed on the ref.guide: we fully agree with you that the documentation lacks on this point. We have done a first stab at improving the guide, mainly the structure of it all. There are however still several topics lacking in clarity. The Reset API is one of them, so my apologies.
@smcvb thank you for the clarification and apologies for putting this in the wrong place. Keep up the great work!
No worries with placing your question here @RabidDog, that's why I shared the regular process with you.
Just happy that it helped you out is all! Let us know if we can answer any other questions you might have. :-)