提交 222d295e 作者: 方治民

fix: 修复 WebSocket 同时适配 Simple 和 STOMP 模式的异常

上级 781d88fe
......@@ -5,6 +5,7 @@ dependencies {
implementation "org.springframework.boot:spring-boot-starter-websocket"
implementation "org.springframework.boot:spring-boot-starter-reactor-netty"
implementation 'org.springframework.boot:spring-boot-starter-amqp'
// hutool
implementation "cn.hutool:hutool-core:${hutoolVersion}"
......
/* (C) 2022 YiRing, Inc. */
package com.yiring.websocket.config;
import cn.hutool.core.convert.Convert;
import cn.hutool.extra.spring.SpringUtil;
import com.yiring.common.core.Redis;
import com.yiring.websocket.constant.RedisKey;
import com.yiring.websocket.interceptor.ClientInboundChannelInterceptor;
import com.yiring.websocket.interceptor.ClientOutboundChannelInterceptor;
import jakarta.annotation.PostConstruct;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
......@@ -39,12 +42,12 @@ public class WebSocketStompConfig implements WebSocketMessageBrokerConfigurer {
public static boolean simpleMode;
public static String mode;
// @PostConstruct
// public void init() {
//// stompPort = Convert.toInt(SpringUtil.getProperty("spring.rabbitmq.stomp-port"));
// simpleMode = Objects.isNull(stompPort);
// mode = simpleMode ? "Simple" : "STOMP";
// }
@PostConstruct
public void init() {
stompPort = Convert.toInt(SpringUtil.getProperty("spring.rabbitmq.stomp-port"));
simpleMode = Objects.isNull(stompPort);
mode = simpleMode ? "Simple" : "STOMP";
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
......
......@@ -53,7 +53,7 @@ public class CustomStompUserRegistry implements StompUserRegistry, SmartApplicat
if (event instanceof SessionConnectedEvent || event instanceof SessionDisconnectEvent) {
SimpMessageHeaderAccessor accessor = handler.getAccessor(message);
Assert.state(accessor != null, "No Accessor");
Assert.state(accessor != null, "No accessor");
String sessionId = accessor.getSessionId();
Assert.state(sessionId != null, "No session id");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论