From db7ab6b32eea3dec065fb9a3ec0b16773a16a5b0 Mon Sep 17 00:00:00 2001 From: wuyuan <15505152113@163.com> Date: Fri, 21 Mar 2025 09:15:54 +0800 Subject: [PATCH] 1 --- .../common/websocket/config/WebSocketConfig.java | 12 ++++++++++-- .../common/websocket/utils/WebSocketUtils.java | 1 + dk-modules/sample/src/main/resources/application.yml | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dk-common/common-websocket/src/main/java/org/dromara/common/websocket/config/WebSocketConfig.java b/dk-common/common-websocket/src/main/java/org/dromara/common/websocket/config/WebSocketConfig.java index ef5cfc9..5d77db5 100644 --- a/dk-common/common-websocket/src/main/java/org/dromara/common/websocket/config/WebSocketConfig.java +++ b/dk-common/common-websocket/src/main/java/org/dromara/common/websocket/config/WebSocketConfig.java @@ -10,8 +10,11 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.web.socket.WebSocketHandler; +import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.config.annotation.EnableWebSocket; import org.springframework.web.socket.config.annotation.WebSocketConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; +import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration; import org.springframework.web.socket.server.HandshakeInterceptor; /** @@ -23,8 +26,13 @@ import org.springframework.web.socket.server.HandshakeInterceptor; @ConditionalOnProperty(value = "websocket.enabled", havingValue = "true") @EnableConfigurationProperties(WebSocketProperties.class) @EnableWebSocket -public class WebSocketConfig { - +public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { + @Override + public void configureWebSocketTransport(WebSocketTransportRegistration registration) { + registration.setSendTimeLimit(15 * 1000); // 消息发送最大超时 + registration.setSendBufferSizeLimit(1024 * 1024); // 发送缓冲区大小 + registration.setMessageSizeLimit(128 * 1024); // 消息大小限制 + } @Bean public WebSocketConfigurer webSocketConfigurer(HandshakeInterceptor handshakeInterceptor, WebSocketHandler webSocketHandler, WebSocketProperties webSocketProperties) { diff --git a/dk-common/common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java b/dk-common/common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java index 5d3ddce..84615e0 100644 --- a/dk-common/common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java +++ b/dk-common/common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java @@ -95,6 +95,7 @@ public class WebSocketUtils { .setBizCode(bizCode); try { + WebSocketMessageDto broadcastMessage = new WebSocketMessageDto(); ObjectMapper mapper = new ObjectMapper(); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); diff --git a/dk-modules/sample/src/main/resources/application.yml b/dk-modules/sample/src/main/resources/application.yml index 1129415..3ddd02f 100644 --- a/dk-modules/sample/src/main/resources/application.yml +++ b/dk-modules/sample/src/main/resources/application.yml @@ -39,7 +39,7 @@ mqtt: # BASIC parameters are required. BASIC: protocol: MQTT - host: 114.235.183.162 + host: 121.237.182.235 port: 1883 username: adminPCBASIC password: yongqiang666 @@ -48,7 +48,7 @@ mqtt: path: DRC: protocol: WS - host: 114.235.183.162 + host: 121.237.182.235 port: 8083 path: /mqtt username: adminPCDRC