0

I'm sending heartbeat using StompJS from Angular using this.client.heartbeat.outgoing = 2000; from this documentation https://stomp-js.github.io/stomp-websocket/codo/extra/docs-src/Usage.md.html

Angular Code

 this.client = new Client({
      brokerURL: 'ws://localhost:8080/gs-guide-websocket',
      onConnect: () => {

        this.client.subscribe('/topic/greetings/' + this.username, (messages: { body }) => {
   
          this.client.heartbeat.outgoing = 2000;

        }

        );
      },

    });
 this.client.activate();
}

I'm not sure how to capture those heartbeats in Spring Boot. I'm doing this because I want to know which clients are connected over WebSocket after every particular interval of time.

My configuration in Spring Boot

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic");
        config.setApplicationDestinationPrefixes("/app");
    }
    
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/gs-guide-websocket").setAllowedOrigins("http://localhost:4200");
        System.out.println("entered the websocket connection");
        
    }

}

I also want to know if we can similarly send heartbeats from server (Spring Boot) to the client?

I'm really new to websockets and not able find any simple implementations of this in the docs of Spring Boot

0 Answers0