"message:Broker not available." error when implementing stomp over spring websocket
Asked Answered
C

2

9

I'm building a sample chat app using spring WebSocket, SockJs and 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. I'm following this Spring Guide.

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)

version: 5.15.0

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

ERROR message:Broker not available. content-length:0

stomp.min.js:8 Whoops! Lost connection to http://localhost:8080/testApp/chat-endpoint

Cinquain answered 5/10, 2019 at 20:30 Comment(0)
K
12

I had the same problem. To fix it I slightly changed configureMessageBroker method:

    @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);
    }
Kreplach answered 14/10, 2019 at 13:51 Comment(0)
R
0

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

Roney answered 29/11, 2022 at 16:46 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Karwan

© 2022 - 2024 — McMap. All rights reserved.