Spring websocket - 集群中的 sendToUser 在备份服务器上不起作用 [英] Spring websocket - sendToUser from a cluster does not work from backup server
问题描述
我们有一个 spring mvc,配置了 spring websocket('spring-websocket',版本:'4.1.0.RELEASE').
We have a spring mvc with spring websocket configured ('spring-websocket', version:'4.1.0.RELEASE').
我们有一个执行以下代码的简单类:
We have a simple class that executes the following code:
@Autowired
private SimpMessagingTemplate template;
@Override
public void push(Long userId, Object message, WebsocketQueue queue) {
String loginName = this.userRepository.getLoginName(userId);
this.template.convertAndSendToUser(
loginName,
queue.getMapping(),
message);
}
这适用于单个 tomcat(非集群环境)
This works great with a single tomcat (non clustered environment)
我们面临的问题是在使用两个 tomcat 的集群时.
The problem we are facing is when working with a cluster of two tomcats.
如果我们尝试将消息从用户登录的实际 tomcat 推送给用户 - 它会起作用.
If we try to push the message to a user from the actual tomcat he was logged in - it works.
但是如果我们尝试从另一个 tomcat 节点推送消息 - 它不会到达用户.
But if we try to push the message from the other tomcat node - it does not reach the user.
1) 我们能做什么?
2) 将 websocket 队列名称更改为用户登录名而不是默认行为对我们有帮助吗?
2) Does changing the websocket queue names to the user login names instead of the default behavior can help us?
推荐答案
这可以通过 Spring Framework 4.2 中添加的功能:
跨服务器集群解析用户目的地
Resolve user destinations across cluster of servers
用户注册可以使用特定的主题目的地广播和分享他们的内容.您可以通过为集群部署配置 StompBrokerRelay
来设置它;见 setUserDestinationBroadcast 和 setUserRegistryBroadcast.
User registries can broadcast and share their content using a specific topic destination. You can set this up by configuring the StompBrokerRelay
for a cluster deployment; see setUserDestinationBroadcast and setUserRegistryBroadcast.
不要犹豫,在 https://jira.spring.io 上发送反馈/改进请求!
Don't hesitate to send feedback / improvement requests on https://jira.spring.io !
这篇关于Spring websocket - 集群中的 sendToUser 在备份服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!