I am new to SockJS, Stomp and Spring websocket. I have spring websocket configuration like below:
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/stomp-endpoint").setAllowedOriginPatterns("*").setAllowedOrigins().withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/topic", "/queue");
registry.setApplicationDestinationPrefixes("/app");
}
I am running multiple instances or deployment of above implementation in my spring applications.
When I access it locally, below code on client side JS works perfect:
var socket = new SockJS("/stomp-endpoint");
stompClient = Stomp.over(socket);
stompClient.connect("", "", function (frame) {
stompClient.subscribe("/topic/publish-updates", function (publishedUpdates) {
showMessages(JSON.parse(publishedUpdates.body));
});
});
Now, I want something like below, so that my single UI code will fetch push notifications from two servers.
var socket1 = new SockJS("http://cml-consumerinstance-ci-0000.com:8080/stomp-endpoint");
stompClient1 = Stomp.over(socket);
stompClient1.connect("", "", function (frame) {
stompClient1.subscribe("http://cml-consumerinstance-ci-0000.com:8080/topic/publish-updates", function (publishedUpdates) {
showMessages(JSON.parse(publishedUpdates.body));
});
});
var socket2 = new SockJS("http://cml-consumerinstance-ci-1111.com:8080/stomp-endpoint");
stompClient2 = Stomp.over(socket);
stompClient2.connect("", "", function (frame) {
stompClient2.subscribe("http://cml-consumerinstance-ci-1111.com:8080/topic/publish-updates", function (publishedUpdates) {
showMessages(JSON.parse(publishedUpdates.body));
});
});
Above code doesn't work.
I tried with "http://cml-consumerinstance-ci-0000.dev3oke2phx.databasede3phx.oraclevcn.com:8080/app/topic/publish-updates" also.
Could someone please help me, how to achieve multiple subscription from different servers?
You should subscribe
/topic/publish-updates, nothttp://cml-consumerinstance-ci-1111.com:8080/topic/publish-updates.