spring-websocket
Spring Websocket in a tomcat cluster
Horizontally scaling WebSockets is actually very different than horizontally scaling stateless/stateful HTTP only based applications. Horizontally Scaling Stateless HTTP app: just spin up some application instances in different machines and put a load balancer in front of them. There are quite a lot different load balancer solutions such as HAProxy, Nginx, etc. If you are … Read more
Spring Boot Websockets in Wildfly
You need exclude tomcat-embed-websocket <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.apache.tomcat.embed</groupId> <artifactId>tomcat-embed-websocket</artifactId> </exclusion> </exclusions> </dependency>
How to send message to client through websocket using Spring
I was able to solve my problem thanks to @Boris the Spider. The correct solution is to do something like that : @Controller @RequestMapping(“https://stackoverflow.com/”) public class PhotoController { @Autowired private SimpMessagingTemplate template; @MessageMapping(“/form”) @SendTo(“/topic/greetings”) public Greeting validate(AddPhotosForm addPhotosForm) { FireGreeting r = new FireGreeting( this ); new Thread(r).start(); return new Greeting(“Hello world !”); } public … Read more
Disconnect client session from Spring websocket stomp server
Actually using some workarounds you can achieve what you want. For that you should do: Use java configuration (not sure if it is possible with XML config) Extend your config class from WebSocketMessageBrokerConfigurationSupport and implement WebSocketMessageBrokerConfigurer interface Create custom sub-protocol websocket handler and extend it from SubProtocolWebSocketHandler class In your custom sub-protocol websocket handler override … Read more
How to reject topic subscription based on user rights with Spring-websocket
Thanks to Rossen Stoyanchev answer on github I was manage to solve this by adding interceptor to the inbound channel. Changes needed in the spring-websocket-portfolio demo application is the following: Change websocket configuration: public void configureClientInboundChannel(ChannelRegistration registration) { registration.setInterceptors(new TopicSubscriptionInterceptor()); } And the interceptor was something like this: public class TopicSubscriptionInterceptor extends ChannelInterceptorAdapter { private … Read more
Spring WebSocket: Handshake failed due to invalid Upgrade header: null
I met the same problem with nginx https proxy to tomcat. This is because I haven’t support the wss request. To support the wss request, I use the config like below: # WebSocketSecure SSL Endpoint # # The proxy is also an SSL endpoint for WSS and HTTPS connections. # So the clients can use … Read more
I get a status 200 when connecting to the websocket, but it is an error?
Please check http://procbits.com/connecting-to-a-sockjs-server-from-native-html5-websocket! After you append /websocket (to your URL), it will give you the error Failed to parse Origin header value [null] 😉 , which then will in turn lead you to that link. You’ll have to add .setAllowedOrigins(“*”) to your addHandler() method, and then it could finally work!
Spring WebSocket @SendToSession: send message to specific session
No need to create specific destinations, it’s already done out of the box as of Spring 4.1 (see SPR-11309). Given users subscribe to a /user/queue/something queue, you can send a message to a single session with: As stated in the SimpMessageSendingOperations Javadoc, since your user name is actually a sessionId, you MUST set that as … Read more
Where “user” comes from in convertAndSendToUser works in SockJS+Spring Websocket?
We know we can send messages to the client from a stomp server using the topic prefixes that he is subscribed to e.g. /topic/hello. We also know we can send messages to a specific user because spring provides the convertAndSendToUser(username, destination, message) API. It accepts a String username which means if we somehow have a … Read more