繁体   English   中英

使用RabbitMQ Web STOMP插件的Spring Boot连接失败

[英]Spring boot connection failure with RabbitMQ Web STOMP Plugin

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

osmssStompBrokerRelayMessageHandler:会话系统中的 TCP连接失败:传输失败:java.lang.IllegalArgumentException:无枚举常量org.springframework.messaging.simp.stomp.StompCommand.HTTP / 1.1 400错误请求

io.netty.handler.codec.DecoderException:java.lang.IllegalArgumentException:No enum constant org.springframework.messaging.simp.stomp.StompCommand.HTTP / 1.1 400错误的请求

以下是我的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>

我正在使用以下类作为Web套接字配置

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经纪人。 我们的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM