修改: webscoket心跳检测优化数据结构
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.sdm.system.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.sdm.common.common.ThreadLocalContext;
|
||||
import com.sdm.common.common.WsMessage;
|
||||
import com.sdm.common.common.WsSceneEnum;
|
||||
@@ -9,7 +9,6 @@ import jakarta.websocket.server.PathParam;
|
||||
import jakarta.websocket.server.ServerEndpoint;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -27,9 +26,6 @@ public class WebSocketServer {
|
||||
// ==================== 修复后:一个用户对应多个Session ====================
|
||||
public static final Map<Long, List<Session>> USER_SESSION_POOL = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
// ==================== 连接建立 ====================
|
||||
@OnOpen
|
||||
public void onOpen(Session session, @PathParam("userId") Long userId) {
|
||||
@@ -86,7 +82,7 @@ public class WebSocketServer {
|
||||
String json="";
|
||||
try {
|
||||
// 1. 用Jackson序列化泛型对象,支持泛型
|
||||
json = objectMapper.writeValueAsString(backMessage);
|
||||
json = JSONObject.toJSONString(backMessage);
|
||||
} catch (Exception e) {
|
||||
log.error("心跳检测失败,WebSocket消息序列化失败,userId:{},scene:{}.-->", backMessage.getUserId(),backMessage.getScene(), e);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user