Reputation: 6532
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);
}
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.
But if we try to push the message from the other tomcat node - it does not reach the user.
1) What can we do?
2) Does changing the websocket queue names to the user login names instead of the default behavior can help us?
Upvotes: 1
Views: 1363
Reputation: 59086
This can be solved with a feature added in 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; see setUserDestinationBroadcast and setUserRegistryBroadcast.
Don't hesitate to send feedback / improvement requests on https://jira.spring.io !
Upvotes: 1