我对SockJS、Stomp和Spring WebSocket都是新手。我有如下的spring WebSocket配置:
@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");
}
我在我的spring
应用程序中运行上述实现的多个示例或部署。当我在本地访问它时,下面的客户端JS代码工作得很好:
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));
});
});
现在,我想要类似下面的东西,这样我的单个UI代码就可以从两个服务器获取推送通知。
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));
});
});
上面的代码不起作用。我也试过"http://cml-consumerinstance-ci-0000.dev3oke2phx.databasede3phx.oraclevcn.com:8080/app/topic/publish-updates"
。
有人可以请帮助我,如何实现多个订阅从不同的服务器?
1条答案
按热度按时间x7rlezfr1#
您应该订阅
/topic/publish-updates
,而不是http://cml-consumerinstance-ci-1111.com:8080/topic/publish-updates
。