<分区>
我们目前正在使用 Spring 的 SimpMessagingTemplate 将 WebSocket 消息从服务器发送到客户端。我们注意到有时消息的接收顺序是乱序的。
例子:
(Autowired) SimpMessagingTemplate broker
broker.convertAndSend(channelId, "Test1");
broker.convertAndSend(channelId, "Test2");
Client receives:
"Test2"
"Test1"
由于 WebSocket 建立在 TCP/IP 之上,这 guarantees order ,我不明白为什么 Spring/SimpMessagingTemplate 会破坏此功能。
我找不到任何关于 SimpMessageTemplate 消息顺序的文档,但是有很多关于“全功能消息代理”的评论,例如 RabbitMQ 和 ActiveMQ。 RabbitMQ 在某些情况下保证消息顺序(不确定这是否适用于 Spring 应用程序上的 WebSocket 消息)。我试着按照this设置了指南,但是 Connection Factory
给我一个 “Could not autowire. No beans of Connection Factory found.”
以防万一我做错了什么,我尝试只下载并运行教程项目 - 但也没有用。它只是显示“构建成功”以及一堆如下所示的调试打印:DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - 在任何属性源中找不到键“spring.liveBeansView.mbeanDomain”。返回 [null]
如何在不破坏协议(protocol)的任何属性的情况下从 Spring 服务器发送 WebSocket 消息?