I want to implement a websocket inside my projet to do something as notifications
this is my configuration web socket in my projet spring boot
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/hello").setAllowedOrigins("*").withSockJS();
}
and in my controller I have this method :
@MessageMapping("/hello")
@SendTo("/topic/templatesWS")
public void TemplatesWebSocket() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("calling juste");
}
and in my client side in my page index.html I added this
<script src="//cdn.jsdelivr.net/sockjs/1/sockjs.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.js"></script>
and in my component angular2 I'm using this
declare let SockJS;
declare let Stomp;
var socket = new SockJS('http://localhost:8080/hello');
socket.ono
var stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
console.log('Connected: ' + frame);
stompClient.subscribe('http://localhost:8080/template/topic/templatesWS', function(greeting) {
console.log("from from", greeting);
});
}, function (err) {
console.log('err', err);
});
How can I call the method TemplatesWebSocket()
