[英]"message:Broker not available." error when implementing stomp over spring websocket
I'm building a sample chat app using spring WebSocket, SockJs and Amazon MQ.我正在使用 spring WebSocket、SockJs 和 Amazon MQ 构建示例聊天应用程序。 It is throwing a 'broker not available' exception when the client subscribes to the topic.
当客户端订阅主题时,它会抛出“代理不可用”异常。 All the inbound traffic rules are set correctly in the AWS security groups, and the broker has stomp support too.
所有入站流量规则都在 AWS 安全组中正确设置,并且代理也有 stomp 支持。 I'm following this Spring Guide .
我正在关注这个Spring 指南。
It works fine if I'm using the in-memory broker.如果我使用内存代理,它工作正常。 I really appreciate your help on this, and the following is the sample code.
非常感谢您对此的帮助,下面是示例代码。
Broker: Amazon MQ (uses Active MQ internally) Broker:Amazon MQ(内部使用 Active MQ)
version: 5.15.0版本:5.15.0
WebSocketConfig.java WebSocketConfig.java
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableStompBrokerRelay("/topic")
.setRelayHost("***********.mq.us-east-2.amazonaws.com").setRelayPort(61614)
.setClientLogin("******").setClientPasscode("*****");
registry.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chat-endpoint").withSockJS();
}
Application Start Log应用程序启动日志
.......
INFO 14280 --- [alina-utility-1] o.s.m.s.s.StompBrokerRelayMessageHandler : Starting...
INFO 14280 --- [alina-utility-1] o.s.m.s.s.StompBrokerRelayMessageHandler : Starting "system" session, StompBrokerRelay[ReactorNettyTcpClient[reactor.netty.tcp.TcpClientDoOn@7acb7b3e]]
INFO 14280 --- [alina-utility-1] o.s.m.s.s.StompBrokerRelayMessageHandler : Started.
......
Client客户
var socket = new SockJS('/chat-endpoint');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {
setConnected(true);
stompClient.subscribe('/topic/message', function(message) {
displayMessage(message); });
});
Browser Console Log浏览器控制台日志
Opening Web Socket... Web Socket Opened... CONNECT accept-version:1.1,1.0 heart-beat:10000,10000
打开 Web 套接字... Web 套接字打开... CONNECT 接受版本:1.1,1.0 心跳:10000,10000
ERROR message:Broker not available.
错误消息:经纪人不可用。 content-length:0
内容长度:0
stomp.min.js:8 Whoops!
stomp.min.js:8 糟糕! Lost connection to http://localhost:8080/testApp/chat-endpoint
失去与http://localhost:8080/testApp/chat-endpoint 的连接
I had the same problem.我有同样的问题。 To fix it I slightly changed configureMessageBroker method:
为了修复它,我稍微更改了 configureMessageBroker 方法:
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
ReactorNettyTcpClient<byte[]> client = new ReactorNettyTcpClient<>(tcpClient -> tcpClient
.host("your-amazon-mq-host.amazonaws.com")
.port(61614)
.secure(SslProvider.defaultClientProvider()), new StompReactorNettyCodec());
registry.setApplicationDestinationPrefixes("/app");
registry.enableStompBrokerRelay("/queue", "/topic")
.setAutoStartup(true)
.setSystemLogin("amazonmq-login")
.setSystemPasscode("amazonmq-pass")
.setClientLogin("amazonmq-login")
.setClientPasscode("amazonmq-pass")
.setTcpClient(client);
}
hello I know how to fix it, okay You should not have the stomp plug-in installed cd /opt/homebrew/opt/rabbitmq/sbin/ rabbitmq-plugins enable rabbitmq_stomp rabbitmq-plugins enable rabbitmq_web_stomp你好,我知道如何修复它,好的 你不应该安装 stomp 插件 cd /opt/homebrew/opt/rabbitmq/sbin/ rabbitmq-plugins enable rabbitmq_stomp rabbitmq-plugins enable rabbitmq_web_stomp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.