While I playing around, I saw a very interesting thing when I re-launch the Spring boot app.
Whenever I re-launch the app, it triggers @EventHandler in OrderedProductsEventHandler class.
It loads all events into the Map. Can somebody explain why this happen?
I believe that what you’re experiencing is an in-memory token store.
A token store keeps track of the position in the event stream that it’s currently at. Usually you would set the token store to be in the same place as the projection (e.g.: in-memory, mysql, redis, mongodb, etc.) As you have not configured JPA or other persistent stores, it’s defaulting to the in-memory version. The in-memory token store is re-created everytime your application stops, therefore it re-processes all the events when it restarts.