Spring Events and service restart

Antamack :

I want to use Spring Events in a Spring Boot service. I've done all the development and the event is published at some point of my code and is received in the listener. So far, so good.

Showing this to a colleague he made a great point. What happens if we restart the service? It may happen that some events are lost?

To provide you more insights, we deploy our services in AWS using Kubernetes. Personally, I don't expect too much load on this service, so the chances to have an event waiting to be consumed while the service is in the shutdown process is quite low. However, it may happen. And also, I'd like to know it in order to use Spring Events in other scenarios or not.

Kayaman :

Spring Events are not meant for "serious" communication. By serious I mean there are no guarantees about reliability, it's just simple message passing between different parts of the application. Hard to say what are the chances that events would be lost even with this, but there's no guarantees.

If you have important messages that can't get lost you need a proper message queue with transactional support. They make guarantees about message delivery, but of course it involves an additional component altogether, and might be overkill for simple things.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=161538&siteId=1