SockJS 从spring websocket 接收stomp 消息乱序 [英] SockJS receive stomp messages from spring websocket out of order

查看:84
本文介绍了SockJS 从spring websocket 接收stomp 消息乱序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Springframework SimpMessagingTemplate(默认 Stomp 实现)流式传输时间序列数据,以将消息广播到 SockJS 客户端订阅的主题.但是,消息是乱序接收的.服务器是单线程的,消息按时间戳升序发送.客户端以某种方式收到了乱序的消息.

I am trying to streaming time series data using Springframework SimpMessagingTemplate (default Stomp implementation) to broadcast messages to a topic that the SockJS client subscribed to. However, the messages is received out of order. The server is single thread and messages are sent in ascending order by their timestamps. The client somehow received the messages out of the order.

我正在使用 stompjs 和 springframework 的最新版本(4.1.6 版本).

I am using the latest release version of both stompjs and springframework (4.1.6 release).

推荐答案

找到了这个问题的根本原因.从应用程序实现的角度来看,消息以正确"的顺序发送(即,convertAndSend() 以一个线程或至少线程安全的方式被调用").然而,Springframework web socket 使用 reactor-tcp 实现,它将在clientOutboundChannel 来自线程池.因此,消息可以按照到达的不同顺序写入 tcp 套接字.当我将 Web 套接字配置为对 clientOutboundChannel 限制 1 个线程时,顺序被保留.

Found the root cause of this issue. The messages were sending in "correct" order from the application implementation perspective (I.e, convertAndSend() are called in one thread or at least thread safe fashion"). However, Springframework web socket uses reactor-tcp implementation which will process the messages on clientOutboundChannel from the thread pool. Thus the messages can be written to the tcp socket in different order that they are arrived. When I configured the web socket to limit 1 thread for the clientOutboundChannel, the order is preserved.

这个问题不在 SocketJS 中,而是当前 Spring web socket 设计的限制.

This problem is not in the SocketJS but a limitation of current Spring web socket design.

这篇关于SockJS 从spring websocket 接收stomp 消息乱序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆