简体   繁体   English

“消息:经纪人不可用。” 在 spring websocket 上执行 stomp 时出错

[英]"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.

相关问题 警告:无法发送消息。 websocket 不可用 - warning: Cannot send message. websocket is not available 没有可用的 package nodejs。 错误:无事可做。 Elastic Beanstalk 上的 Rails 应用程序 - No package nodejs available. Error: Nothing to do. Rails App On Elastic Beanstalk 部署错误。 构建失败:构建错误详细信息不可用。 Firebase 云函数 - Deployment error. Build failed: Build error details not available. Firebase Cloud Functions 登录选项不可用。 请尝试另一个 - Login option is not available. Please try another one Axios 上传资产超过大小限制时不从 S3 返回 XML 错误消息 - Axios does not return XML error message from S3 when uploading asset over the size limit 无法通过 websockets 发布到 aws mqtt 代理 - Cant publish to aws mqtt broker over websockets 无法让 Google Cloud Platform 识别 JSON 服务帐户密钥文件。 错误:PyOpenSSL 不可用。 建议使用 JSON,但我使用的是 JSON 密钥 - Can't get Google Cloud Platform to recognize JSON service account key file. Error: PyOpenSSL is not available. Suggests JSON but I'm using a JSON key 无法打开到 amazonmq 的直接 websocket 连接(无 stomp) - Unable to open direct websocket connection (without stomp) to amazonmq WebSocket 服务在通过Azure API 管理时收到客户端消息后总是关闭连接 - WebSocket service always closes the connection after receiving a message from the client when connecting through Azure API Management 运行集成了 Firestore 的应用程序时,“由于错误 9,GooglePlayServices 不可用” - "GooglePlayServices not available due to error 9" when running an app with Firestore integrated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM