Stomp Web套接字在tomcat单实例中运行良好。但是,当两个实例启动时,它将无法正常工作。我正在使用Spring Boot应用程序和VueJS frontEnd。
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/connect-to-websocket")
.setAllowedOrigins("*")
.withSockJS();
}
}
在执行一些操作后,我正在使用像这样的模板。
this.template.convertAndSend("/Auction/currentPrice",auctionDetailsSocketEntity);
因此,曾经订阅/ Auction / currentPrice的人将收到此数据。
我只发布过曾经订阅过的消息。
这对于一个实例工作正常。但是有两个实例无法正常工作。如何解决。预先感谢
答案 0 :(得分:0)
@RajaSekhar Chodavarapu,尝试一下...
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(final MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(final StompEndpointRegistry registry) {
registry.addEndpoint("/connect-to-ebsocket").setAllowedOrigins("*").withSockJS();
}
}