How to use STOMP heartbeats in web and spring?

Viewed 3118

Now I'm using stomp to connect from web to server.

I know STOMP has a heartbeat mechanism after v1.1, also I've already set it successfully. But I don't know how to detect/catch PING/PONG frame and handle it.

The code in web like this:

    this.stomp = Stomp.client(this.wsUrl);
    this.stomp.heartbeat.outgoing = 5000;
    this.stomp.heartbeat.incoming = 5000;
    this.stomp.connect({}, (frame: any) => {
    // ...
    }, (error: any) => {
    // ...
    });

The code in server like this. we use spring stomp.

    public void configureMessageBroker(MessageBrokerRegistry config) {
    config.enableSimpleBroker("/topic")
            .setTaskScheduler(new DefaultManagedTaskScheduler())
            .setHeartbeatValue(new long[] {5000, 5000});
    config.setApplicationDestinationPrefixes("/signal");
}

I can see PING/PONG frame printed in the console panel in chrome.

0 Answers
Related