From 0e7c7e8033ffdf67194bf40b9198cdf2a435fa13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 8 Oct 2024 14:44:45 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=20=E5=90=8C=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=94=A8=E6=88=B7=E4=B8=8D=E5=90=8Ctoken=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E4=B8=8D=E5=90=8C=E6=9C=8D=E5=8A=A1=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=8F=91=E9=80=81=E4=B8=8D=E5=88=B0=E9=97=AE=E9=A2=98(?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=85=A8=E5=B1=80=E5=8F=91=E9=80=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/sse/core/SseEmitterManager.java | 26 +++++-------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java b/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java index 1d37a27d..5e48e072 100644 --- a/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java +++ b/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java @@ -124,25 +124,13 @@ public class SseEmitterManager { * @param sseMessageDto 要发布的SSE消息对象 */ public void publishMessage(SseMessageDto sseMessageDto) { - List unsentUserIds = new ArrayList<>(); - // 当前服务内用户,直接发送消息 - for (Long userId : sseMessageDto.getUserIds()) { - if (USER_TOKEN_EMITTERS.containsKey(userId)) { - sendMessage(userId, sseMessageDto.getMessage()); - continue; - } - unsentUserIds.add(userId); - } - // 不在当前服务内用户,发布订阅消息 - if (CollUtil.isNotEmpty(unsentUserIds)) { - SseMessageDto broadcastMessage = new SseMessageDto(); - broadcastMessage.setMessage(sseMessageDto.getMessage()); - broadcastMessage.setUserIds(unsentUserIds); - RedisUtils.publish(SSE_TOPIC, broadcastMessage, consumer -> { - log.info("SSE发送主题订阅消息topic:{} session keys:{} message:{}", - SSE_TOPIC, unsentUserIds, sseMessageDto.getMessage()); - }); - } + SseMessageDto broadcastMessage = new SseMessageDto(); + broadcastMessage.setMessage(sseMessageDto.getMessage()); + broadcastMessage.setUserIds(sseMessageDto.getUserIds()); + RedisUtils.publish(SSE_TOPIC, broadcastMessage, consumer -> { + log.info("SSE发送主题订阅消息topic:{} session keys:{} message:{}", + SSE_TOPIC, sseMessageDto.getUserIds(), sseMessageDto.getMessage()); + }); } /**