RabbitMQ - StompBrokerRelayMessageHandler - 收到错误{message = [Bad CONNECT]

时间:2016-05-02 14:28:17

标签: spring spring-boot rabbitmq

我正在使用reactor-spring-core,2.0.7.RELEASE。 尝试连接到RabbitMQ并获取:

StompBrokerRelayMessageHandler - 收到错误{message = [Bad CONNECT]

知道为什么吗?

提前致谢: - )

2 个答案:

答案 0 :(得分:1)

如果您将spring boot stomp与rabbitmq一起使用,此配置解决了该问题-

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketChatConfig implements WebSocketMessageBrokerConfigurer {

    private final String rabbitHost;
    private final int rabbitStompPort;
    private final String rabbitUser;
    private final String rabbitPass;

    public WebSocketChatConfig(@Value("${RABBITMQ_HOST}") String rabbitHost,
                               @Value("${RABBITMQ_STOMP_PORT}") String rabbitStompPort,
                               @Value("${RABBITMQ_USER}") String rabbitUser,
                               @Value("${RABBITMQ_PASS}") String rabbitPass) {
        this.rabbitHost = rabbitHost;
        this.rabbitStompPort = Integer.parseInt(rabbitStompPort);
        this.rabbitUser = rabbitUser;
        this.rabbitPass = rabbitPass;
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocketApp").setAllowedOrigins("*").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.setApplicationDestinationPrefixes("/app");

        registry.enableStompBrokerRelay("/topic")
                .setRelayHost(rabbitHost)
                .setRelayPort(rabbitStompPort)
                .setClientLogin(rabbitUser)
                .setClientPasscode(rabbitPass)
                .setSystemLogin(rabbitUser)
                .setSystemPasscode(rabbitPass);
    }
}

注意:需要setSystemLogin和setSystemPasscode(在文档中未提及,花了2个小时才弄清),因为RabbitMq使用SystemLogin(默认:“ guest”)和systemPasscode(默认:guest)来连接心跳< / p>

答案 1 :(得分:0)

修正了它! : - )

应该在rabbitmq.config中输入以下内容:

[{rabbit,[{loopback_users,[]}]}]。

它将与来宾/访客凭证一起使用: - )