Spring RabbitMQ Web STOMP 插件启动连接失败

Spring boot connection failure with RabbitMQ Web STOMP Plugin

我正在尝试将 RabbitMQ Web STOMP 插件与 Spring 引导一起使用。我已经启动了 RabbitMQ 服务器,并为 http/web-stomp 协议公开了 15674 端口。当我 运行 Spring 引导项目时,出现以下错误

o.s.m.s.s.StompBrokerRelayMessageHandler : TCP connection failure in session system: Transport failure: java.lang.IllegalArgumentException: No enum constant org.springframework.messaging.simp.stomp.StompCommand.HTTP/1.1 400 Bad Request

io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: No enum constant org.springframework.messaging.simp.stomp.StompCommand.HTTP/1.1 400 Bad Request

下面是我的 pom.xml 依赖项

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-core</artifactId>
        <version>3.2.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>io.projectreactor.netty</groupId>
        <artifactId>reactor-netty</artifactId>
        <version>0.8.2.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.0.33.Final</version>
    </dependency>
</dependencies>

我使用以下 class 作为网络套接字配置

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration implements 
WebSocketMessageBrokerConfigurer {

   @Override
   public void configureMessageBroker(MessageBrokerRegistry registry) {
       registry.setApplicationDestinationPrefixes("/app")
               .enableStompBrokerRelay("/topic")
               .setRelayHost("localhost")
               .setRelayPort(15674)
               .setClientLogin("guest")
               .setClientPasscode("guest");
}

   @Override
   public void registerStompEndpoints(StompEndpointRegistry registry) {
       registry.addEndpoint("/websocket").withSockJS();

   }
}

下面是我的 RabbitMQ Web 插件的快照,其中显示了暴露的端口

有人可以帮忙吗?

relay 的端口错误。查看该屏幕截图上的插件配置。 STOMP 端口是 61613。而这个正是 StompBrokerRelayRegistration:

中的默认值
public class StompBrokerRelayRegistration extends AbstractBrokerRegistration {

    private String relayHost = "127.0.0.1";

    private int relayPort = 61613;

    private String clientLogin = "guest";

    private String clientPasscode = "guest";

    private String systemLogin = "guest";

    private String systemPasscode = "guest";

不确定您为什么决定为您的应用程序使用 http/web-stomp 插件:https://www.rabbitmq.com/web-stomp.html

我们在这里谈论的正是 STOMP Broker。我们的 Spring 应用程序将成为该应用程序的 WebSocket 代理。 Web STOMP RabbitMQ 插件用于目标 WebSocket 客户端。这不适用于服务器端通过 STOMP Broker 进行中继。

只需使用为 STOMP 插件公开的端口。一切都应该工作正常。您也可以在 pom.xml

中添加这些依赖项
<!-- RabbitMQ Starter Dependency -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

<!-- Following additional dependency is required for Full Featured STOMP Broker Relay -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-reactor-netty</artifactId>
</dependency>