5

I am using Spring Websocket with SockJs (v1.1.1) over STOMP on client. I create the client with the code below.

SockJS = require('sockjs-client') Stomp = require('webstomp-client') stompClient = Stomp.over(new SockJS(url)) 

It's works fine. But it uses xhr_streaming as transport by default, that is not desirable for me. I want to switch it to websocket tranport.

stompClient = Stomp.over(new SockJS(url, null, {transports:'websocket'})) 

But this approach does not work for me. It falls with event:

code: 2000 reason: "All transports failed" 

My Spring Websocket configuration is very simple:

@Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractSessionWebSocketMessageBrokerConfigurer<ExpiringSession> { @Override public void configureStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint("/myEndpoint").setAllowedOrigins("*") .withSockJS(); } @Override public void configureMessageBroker(MessageBrokerRegistry registry) { registry.enableSimpleBroker("/queue/", "/topic/"); registry.setApplicationDestinationPrefixes("/app"); } } 

The main problem I face with xhr_streaming is that every stream request updates last access time for user session (I use Spring Session as well). But it's not a desirable behavior for my application. So how I can fix it? And will websocket transport help? Thanks in advance.

1 Answer 1

6

So, I've got the reason. I am using a webpack dev server with proxy option. By default it does NOT proxy ws protocol requests (it losts headers). You need toa add ws: true to your config and everything will work fine.

proxy: { '/api/*': { target: 'http://localhost:8080', pathRewrite: {'^/api' : ''}, ws: true } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.