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.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) {

1
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);

4
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

Loading…
Cancel
Save