refactor(message): 优化SSE会话注册表的容器关闭事件处理
- 移除@PreDestroy注解 - 添加ContextClosedEvent事件监听器 - 使用Spring事件机制替代JSR-250生命周期回调 - 提高容器关闭时SSE连接清理的可靠性 - 增强代码的Spring框架集成一致性
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
package com.youlai.boot.message.registry;
|
||||
|
||||
import com.youlai.boot.message.dto.OnlineUserDTO;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.ContextClosedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
@@ -198,7 +199,7 @@ public class SseSessionRegistry {
|
||||
/**
|
||||
* 容器关闭时主动断开所有 SSE 连接,避免阻塞应用停止
|
||||
*/
|
||||
@PreDestroy
|
||||
@EventListener(ContextClosedEvent.class)
|
||||
public void destroy() {
|
||||
int count = emitterUserMap.size();
|
||||
if (count == 0) {
|
||||
|
||||
Reference in New Issue
Block a user