feat(property): 用 Server-Sent Events (SSE) 替代 WebSocket 实现消息推送

This commit is contained in:
2025-09-06 13:16:40 +08:00
parent 22c6efea63
commit 0bf8cf45e8
8 changed files with 111 additions and 38 deletions

View File

@@ -23,4 +23,13 @@ public interface RemoteMessageService {
* @param message 消息内容
*/
void publishAll(String message);
/**
* 向指定的用户的指定会话发送消息
*
* @param userId 要发送消息的用户id
* @param token 用户的会话令牌
* @param message 要发送的消息内容
*/
void sendMessage(Long userId, String token, String message);
}

View File

@@ -44,4 +44,20 @@ public class RemoteMessageServiceStub implements RemoteMessageService {
log.warn("推送功能未开启或服务未找到");
}
}
/**
* 向指定的用户的指定会话发送消息
*
* @param userId 要发送消息的用户id
* @param token 用户的会话令牌
* @param message 要发送的消息内容
*/
@Override
public void sendMessage(Long userId, String token, String message) {
try {
remoteMessageService.sendMessage(userId, token, message);
} catch (Exception e) {
log.warn("推送功能未开启或服务未找到");
}
}
}