Browse Source

1

pull/1/head
吴远 3 months ago
parent
commit
db7ab6b32e
  1. 12
      dk-common/common-websocket/src/main/java/org/dromara/common/websocket/config/WebSocketConfig.java
  2. 1
      dk-common/common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java
  3. 4
      dk-modules/sample/src/main/resources/application.yml

12
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.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.WebSocketHandler; 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.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer; 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; import org.springframework.web.socket.server.HandshakeInterceptor;
/** /**
@ -23,8 +26,13 @@ import org.springframework.web.socket.server.HandshakeInterceptor;
@ConditionalOnProperty(value = "websocket.enabled", havingValue = "true") @ConditionalOnProperty(value = "websocket.enabled", havingValue = "true")
@EnableConfigurationProperties(WebSocketProperties.class) @EnableConfigurationProperties(WebSocketProperties.class)
@EnableWebSocket @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 @Bean
public WebSocketConfigurer webSocketConfigurer(HandshakeInterceptor handshakeInterceptor, public WebSocketConfigurer webSocketConfigurer(HandshakeInterceptor handshakeInterceptor,
WebSocketHandler webSocketHandler, WebSocketProperties webSocketProperties) { WebSocketHandler webSocketHandler, WebSocketProperties webSocketProperties) {

1
dk-common/common-websocket/src/main/java/org/dromara/common/websocket/utils/WebSocketUtils.java

@ -95,6 +95,7 @@ public class WebSocketUtils {
.setBizCode(bizCode); .setBizCode(bizCode);
try { try {
WebSocketMessageDto broadcastMessage = new WebSocketMessageDto(); WebSocketMessageDto broadcastMessage = new WebSocketMessageDto();
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE); mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);

4
dk-modules/sample/src/main/resources/application.yml

@ -39,7 +39,7 @@ mqtt:
# BASIC parameters are required. # BASIC parameters are required.
BASIC: BASIC:
protocol: MQTT protocol: MQTT
host: 114.235.183.162 host: 121.237.182.235
port: 1883 port: 1883
username: adminPCBASIC username: adminPCBASIC
password: yongqiang666 password: yongqiang666
@ -48,7 +48,7 @@ mqtt:
path: path:
DRC: DRC:
protocol: WS protocol: WS
host: 114.235.183.162 host: 121.237.182.235
port: 8083 port: 8083
path: /mqtt path: /mqtt
username: adminPCDRC username: adminPCDRC

Loading…
Cancel
Save