问题
I'm testing clustering of spring sessions websocket sample.
I'm running the sample as described in docs: http://docs.spring.io/spring-session/docs/current/reference/html5/guides/websocket.html. Code from: https://github.com/spring-projects/spring-session/archive/1.2.2.RELEASE.zip.
If I run the app on one Tomcat server, all works as expected. but If I run two apps on two servers all does not work.
I start the app on each of two Tomcat servers at 8080 and 8090 and login to each. 8080 comes up as expected. 8090 comes up as expected and lists the user name for 8080. But the user name for 8090 is never added to the list on 8080.
If I refresh the web page for 8090 the user is removed from the list and the user for 8090 is added to the list for 8080. This cycle continues with both apps.
It appears spring sessions is sharing session info. I see entries in Redis for both logins.
Should I expect this sample to run across multiple servers?
thanks in advance.
回答1:
I assume that you have configured a stomp broker relay and that you used the AbstractSessionWebSocketMessageBrokerConfigurer
class to configure WebSocket with spring session.
After that, cluster still not works because the default publish mechanism use a local sessionsRepository
to resolve socket id for a user. We don't want this mechanism. We need to use a remote repository.
The remoteRepository
already exists in spring
. To active it you just have to configure your MessageBrokerRegistry :
registry.enableStompBrokerRelay("/topic/", "/queue/", "/exchange/") .setUserDestinationBroadcast("/topic/logbook-unresolved-user") .setUserRegistryBroadcast("/topic/logbook-user-registry")
It works fine for me. I hope that it will help.
来源:https://stackoverflow.com/questions/40429190/websocket-sessions-sample-doesnt-cluster-spring-session-1-2-2