Hi,

We are using spring-boot 2.6.3 (Also tested with spring boot 2.6.7) with the websocket libraries. I have configured the WebSocketMessageBroker accordingly:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket")
            .setAllowedOrigins("*");
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.setApplicationDestinationPrefixes("/app")
                .enableSimpleBroker("/topic")
                .setHeartbeatValue(new long[] {10000, 10000})
                .setTaskScheduler(new DefaultManagedTaskScheduler());
    }

}

The client is an Angular appliction which uses RxStomp which is configured as follow:

brokerURL: environment.wsUrl,
connectHeaders: {},
heartbeatIncoming: 10000,
heartbeatOutgoing: 10000,
reconnectDelay: 5000,

When I check the traffic in the webbrowser, I can see that the Client sends:

CONNECT
Authorization:Bearer MASKED
accept-version:1.0,1.1,1.2
heart-beat:10000,10000

and the server response is:

CONNECTED
version:1.2
heart-beat:0,0

So the MessageBroker configuration that I set in spring boot does not seem to have any affect. I have search stackoverflow for the issue and tried a lot of different solutions from there but non have any affect. Please advise what is wrong? The affect of this is that the client reconnect to the server every 1 minute and 5 sec since it thinks that the connection is broken.

Comment From: wilkinsona

Thanks for the report. I can't spot anything that's obviously wrong from what you have shared thus far. Setting the task scheduler alone should be sufficient to configure 10s heart beats. The response to the CONNECT is sent by org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler.handleMessageInternal(Message<?>). You could try debugging your application and looking at the handler's state and the behaviour of this method to determine why the heart-beat:0,0 header is being sent. If that doesn't allow you to diagnose the cause and you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: amiknyg

Hi Andy, Thank you so much for the quick response!

I have now debuged the application and found that is was a missconfiguration from my part! The angular application pointed to a service where I hadent added the code:

.setHeartbeatValue(new long[] {10000, 10000})
.setTaskScheduler(new DefaultManagedTaskScheduler());

Im so sorry for taking your time, but your suggestion was very helpfull, because I found right away that the breakpoint wasent fired.. so.. Thanks so much! When I fixed the missconfiguration I could see that se server does actually set heart-beat 10000, 10000 and now the connection is not loss

Comment From: wilkinsona

@amiknyg I'm pleased to hear it helped. Thanks for letting us know.