带有RabbitMQ Web STOMP插件的春季启动连接失败

时间:2018-11-25 12:42:42

标签: java spring-boot rabbitmq stomp stomp-websocket

我正在尝试在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:没有枚举常量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插件的快照,其中显示了暴露的端口

enter image description here

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

您的 MediaScannerConnection.scanFile(this, new String[]{file.toString()}, null, new MediaScannerConnection.OnScanCompletedListener() { public void onScanCompleted(String path, Uri uri) { Log.i("ExternalStorage", "Scanned " + path + ":"); Log.i("ExternalStorage", "-> uri=" + uri); image_path = uri.toString(); Intent intent = new Intent(context,Activity2.class); intent.putExtra("image_path", image_path); startActivity(intent); } }); 端口错误。在该屏幕截图上查看您的插件配置。 STOMP端口为 String imageFilePath = getIntent().getStringExtra("image_path"); 。而这正是relay中的默认值:

61613

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

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

答案 1 :(得分:0)

只需使用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>