简体   繁体   English

春季事件生命周期

[英]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 应用程序上下文中,如果应用程序崩溃就会消失,我的猜测是否正确?

Spring events are intended to use when calling methods directly would create too much coupling.当直接调用方法会产生过多的耦合时,应使用 Spring 事件。 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合并支持消息持久性的消息代理,例如Kafka
  3. Install an in-memory cache such as Hazelcast安装内存缓存,例如Hazelcast
  4. Use a cloud message service such as AWS SQS使用云消息服务,例如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.选项 2 到 4 都引入了严重的复杂性,分布式应用程序会给你的生活带来悲伤和痛苦。 Go for the simplest option if you can and only resort the other options if absolutely necessary.如果可以,请选择最简单的选项,并且仅在绝对必要时才使用其他选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM