Spring Boot Websocket中的处理程序传输错误

时间:2019-03-20 08:24:26

标签: spring-boot spring-websocket

我在spring-boot 1.5.8中实现了websocket,在本地运行良好,但是当我部署到服务器(在嵌入式服务器中运行)时,来自服务器的通知消息不稳定,有时客户端有时会收到消息不是。

我检查日志并收到一条消息

2019-03-20 08:04:08.723  INFO 15506 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats    : WebSocketSession[2 current WS(2)-HttpStream(0)-HttpPoll(0), 167 total, 0 closed abnormally (0 connect failure, 0 send limit, 27 transport error)], stompSubProtocol[processed CONNECT(107)-CONNECTED(107)-DISCONNECT(2)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1149], outboundChannelpool size = 0, active threads = 0, queued tasks = 0, completed tasks = 306], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 4, completed tasks = 4468]

(0 connect failure, 0 send limit, 27 transport error)

日志消息显示27条消息错误,我不知道该如何解决。

我们可以处理错误消息事件来解决此问题吗?

更新

我的websocket服务器

 @Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS();
}

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.setApplicationDestinationPrefixes("/queue");
    registry.enableSimpleBroker("/notify", "/queue", "/user");
    registry.setUserDestinationPrefix("/user");
}

在客户端

function connect() {

    var socket = new SockJS('http://localhost:8080/ws/');
    var stompClient = Stomp.over(socket);
    stompClient.connect({}, function(frame) {
      stompClient.subscribe('/user/queue/notify', function(notification) {
          notify(notification.body)
      });
    });

    return;
  } 

  /**
   * Display the notification message.
   */
  function notify(message) {
    $("#notifications-area").append(message + "\n");
    return;
  }

0 个答案:

没有答案