8

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

Vishnu S Kumar
  • 666
  • 7
  • 24

2 Answers2

10

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);
    }
Maciej
  • 116
  • 1
  • 3
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

Jano
  • 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](/help/how-to-answer). – Community Dec 05 '22 at 16:13