spring-boot - spring boot 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;
}
解决方案
推荐阅读
- sql - sql 正则表达式字符串以“.0”结尾
- vue.js - Vue,分离出组件模板
- c# - 将 Excel 字节数组数据转换为 Datatable C# API
- sql - 尝试构造 PostgreSQL 查询以从 JSON 中提取对象、数组、对象、数组、对象中的文本值
- javascript - 如何根据布尔值自动移动 JSON 数据
- c++ - OpenCV x86 缺少数百个 DLL
- php - 访问 CURL 请求的结果
- python - 根据最大值(最后一项)、最小值(第一项)和使用二分搜索的搜索值估计要搜索的项的位置
- python - 字符串未正确从 pandas 数据帧输出到 .CSV
- apache-spark - 如何知道火花中一个阶段使用的核心数量