I have a server socket implemented with spring boot and Angular 7 web page implemented like client
For using websocket on the server I have the next configuration
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/alerts", "/transfers");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/expiredControl-ws")
.setAllowedOrigins("*").withSockJS()
.setWebSocketEnabled(false)
.setInterceptors(httpHandshakeInterceptor());
}
@Bean
public HttpHandshakeInterceptor httpHandshakeInterceptor() {
return new HttpHandshakeInterceptor();
}
}
and for implementing the websocket client I have this configuration
import {Injectable} from "@angular/core";
import * as SockJS from 'sockjs-client';
import * as Stomp from '@stomp/stompjs';
@Injectable()
export class WebSocketService {
// Open connection with the back-end socket
public connect() : Promise<Stomp.Client> {
return new Promise((resolve) => {
const stompClient = new Stomp.Client({
webSocketFactory: () => {
return new SockJS('/expiredControlWs/expiredControl-ws');
},
debug:(args) => {
console.log("WebSocketService" , args);
},
onConnect: () => {
resolve(stompClient);
},
onDisconnect: () => {
console.log("WebSocketService disconnected");
},
reconnectDelay: 5000,
heartbeatIncoming: 4000,
heartbeatOutgoing: 4000
});
stompClient.activate();
});
}
}
Dependencies that i am using:
---back-end
spring 5.0.12.RELEASE,
spring-boot: 2.0.6.RELEASE,
spring-websocket-5.0.12.RELEASE
"@stomp/stompjs": "^5.4.2",
"sockjs-client": "^1.3.0",
Additionally I am using keyloack as security framework.
So, What is my problem?
After I done a rest request the websocket client connection dead, but this does not happen inmediatly.
After I have done a rest request when I want to send data from the client to the server, the client connection is closed. I have no idea why this happends?