Skip to content

Spring event lifecycle

To understand if the spring events fits the task im working on I need to understand how they work, where are they stored? as I can guess they are stored in a spring application context and disappears if the application crashes, is my guess correct?



Spring events are intended to use when calling methods directly would create too much coupling. If you need to track events for auditing or replay purposes you have to save the events yourself. Based on your comments, there are many ways to achieve this, based on the topology and purpose of the application (list not complete):

  1. Model entities that represent the events and store them in a repository
  2. Incorporate a message broker such as Kafka that support message persistence
  3. Install an in-memory cache such as Hazelcast
  4. Use a cloud message service such as AWS SQS

Lastly, please make sure that you carefully evaluate which options suits your needs best. Options 2 to 4 all introduce heavy complexity and distributed applications can bring sorrow and misery to your life. Go for the simplest option if you can and only resort the other options if absolutely necessary.

10 People found this is helpful