fix: SSE连接关闭时机提前至容器关闭最早阶段

添加@Order(Ordered.HIGHEST_PRECEDENCE)确保最高优先级执行,
在Tomcat关闭前主动断开所有SSE连接,避免阻塞应用停止
This commit is contained in:
Ray.Hao
2026-04-03 10:14:11 +08:00
parent b411baaddd
commit 9927546b78

View File

@@ -4,6 +4,8 @@ import com.youlai.boot.message.dto.OnlineUserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
@@ -199,6 +201,7 @@ public class SseSessionRegistry {
/**
* 容器关闭时主动断开所有 SSE 连接,避免阻塞应用停止
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
@EventListener(ContextClosedEvent.class)
public void destroy() {
int count = emitterUserMap.size();