我是websocket的新手。经过介绍原型(https://www.baeldung.com/websockets-spring)并使其正常工作。但是,当尝试使用真实的代理配置STOMP(使用ActiveMQ,因为这是我们在其他地方使用的代理)时,会出现一些奇怪的行为:
通道对于toTransport连接无效:tcp:// xxx失败:org.apache.activemq.transport.InactivityIOException:通道也无效(> 20000)长
也许由于我的知识有限,它与HeartBeat配置有关,似乎无法深入了解...
非常感谢您的帮助。
包括Spring Broker配置:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketAmqConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.setApplicationDestinationPrefixes("/app");
config.enableStompBrokerRelay("/topic")
.setRelayHost("127.0.0.1")
.setRelayPort(61613).setSystemHeartbeatReceiveInterval(0).setSystemHeartbeatSendInterval(10000);
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chat");
registry.addEndpoint("/chat").withSockJS();
}
}
ActiveMQ配置:
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
客户端配置:
function connect() {
var socket = new SockJS('/websoc-prototype/rest/chat');
stompClient = Stomp.over(socket);
stompClient.heartbeat.outgoing = 20000;
stompClient.heartbeat.incoming = 0;
stompClient.connect({}, function(frame) {
setConnected(true);
console.log('Connected: ' + frame);
stompClient.subscribe('/topic/messages', function(messageOutput) {
showMessageOutput(JSON.parse(messageOutput.body));
});
});
}