update 重构 common-sse 与 common-websocket 合并为 ruoyi-common-push 推送模块

This commit is contained in:
疯狂的狮子Li
2026-03-26 17:25:36 +08:00
parent 40011e9acd
commit 029f6a4c11
45 changed files with 775 additions and 1132 deletions

View File

@@ -1,14 +1,18 @@
package org.dromara.demo.controller;
import org.dromara.common.core.domain.R;
import org.dromara.common.websocket.dto.WebSocketMessageDTO;
import org.dromara.common.websocket.utils.WebSocketUtils;
import org.dromara.common.core.domain.dto.PushPayload;
import org.dromara.common.core.enums.PushSourceEnum;
import org.dromara.common.core.enums.PushTypeEnum;
import org.dromara.common.push.helper.PushHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* WebSocket 演示案例
*
@@ -23,11 +27,22 @@ public class WebSocketController {
/**
* 发布消息
*
* @param dto 发送内容
* @param userId 目标用户
* @param message 发送内容
*/
@GetMapping("/send")
public R<Void> send(WebSocketMessageDTO dto) throws InterruptedException {
WebSocketUtils.publishMessage(dto);
public R<Void> send(Long userId, String message) {
PushPayload payload = PushPayload.of(
PushTypeEnum.MESSAGE,
PushSourceEnum.BACKEND,
message,
null
);
if (userId == null) {
PushHelper.publishAll(payload);
} else {
PushHelper.publishMessage(List.of(userId), payload);
}
return R.ok("操作成功");
}
}