Reputation: 1227
I put Event Handler to query my events in axon framework in my spring application. I can put an event from my command up and I can read them from my query app.until reboot time no problem But when I reboot my query app Each time it reads same events again at the beginning and it cause duplicate process. How can I commit an event when I read it?
ToMyAxonConfig
@Bean
public TokenStore tokenStore(Serializer serializer, EntityManagerProvider entityManagerProvider) {
return JpaTokenStore.builder()
.entityManagerProvider(entityManagerProvider)
.serializer(serializer)
.build();
}
@Autowired
public void configureProcessors(EventProcessingConfigurer eventProcessingConfigurer) {
TrackingEventProcessorConfiguration tepConfig = TrackingEventProcessorConfiguration.forSingleThreadedProcessing().andInitialTrackingToken(StreamableMessageSource::createHeadToken);
eventProcessingConfigurer.registerTrackingEventProcessorConfiguration(config -> tepConfig);
}
Upvotes: 2
Views: 790
Reputation: 1920
I have the feeling you haven't configured a TokenStore
.
In that case, Axon Framework will give you an InMemoryTokenStore
implementation meaning that on every restart, you will get all Events again from your Event Store because your app does not have a 'state' for the token.
You can check the ref-guide to know more about it and also how to configure one properly from several options.
How can I commit an event when I read it?
Also to correct a bit the word usage here, Events are 'commited' on your Event Store. If you are talking about your Query Side App, you do not commit Events there but you just save a state based on Events.
Upvotes: 1