我使用此tutorial作为指南,已成功使用Spring Boot实现了一个简单的websockets应用程序。该应用程序可以成功连接到STOMP端点,订阅该主题并获得回复。
为了保持这一微服务趋势的一切,我一直在努力使客户端外部的春季启动应用程序。我可以使用std::unique_ptr<>
成功连接到STOMP端点但是,我不能按照预期使用std::shared_ptr<>
订阅并从spring boot应用程序获取更新。
有没有办法在外部订阅http://localhost:8080/delivery-ws
?
WebSocketConfig.java
http://localhost:8080/topic/openDeliveries
DeliveryController.java
topic/openDeliveries
的index.html
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/delivery-ws").setAllowedOrigins("*").withSockJS();
}
}
答案 0 :(得分:1)
您需要更改您要订阅的网址。像这样:
stompClient.subscribe('/topic/openDeliveries', function(deliveryList) {
console.log('in callback for opendelivery topic');
showDeliveries(deliveryList);
});
一旦连接到套接字端点,就不需要在订阅中定义主机和端口。