简体   繁体   English

Spring WebSocket-群集中的sendToUser在备份服务器上不起作用

[英]Spring websocket - sendToUser from a cluster does not work from backup server

We have a spring mvc with spring websocket configured ('spring-websocket', version:'4.1.0.RELEASE'). 我们有一个配置了spring websocket的spring mvc('spring-websocket',版本:'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);

}

This works great with a single tomcat (non clustered environment) 这对于单个雄猫(非集群环境)非常有效

The problem we are facing is when working with a cluster of two tomcats. 我们面临的问题是使用两个雄猫的集群。

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. 但是,如果我们尝试从另一个tomcat节点推送消息-它不会到达用户。

1) What can we do? 1)我们该怎么办?

2) Does changing the websocket queue names to the user login names instead of the default behavior can help us? 2)将websocket队列名称更改为用户登录名而不是默认行为是否对我们有帮助?

This can be solved with a feature added in Spring Framework 4.2 : 这可以通过在Spring Framework 4.2中添加的功能来解决:

Resolve user destinations across cluster of servers 解决服务器集群中的用户目标

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; 您可以通过为集群部署配置StompBrokerRelay来进行设置。 see setUserDestinationBroadcast and setUserRegistryBroadcast . 请参见setUserDestinationBroadcastsetUserRegistryBroadcast

Don't hesitate to send feedback / improvement requests on https://jira.spring.io ! 请随时在https://jira.spring.io上发送反馈/改进请求!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM