mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-04-10 04:23:16 +08:00
update 重构 common-sse 与 common-websocket 合并为 ruoyi-common-push 推送模块
This commit is contained in:
@@ -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("操作成功");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user