【问题标题】:Spring boot + ActiveMQ + stomp broker relay failed to connectSpring boot + ActiveMQ + stomp broker 中继连接失败
【发布时间】:2016-06-08 16:08:48
【问题描述】:

我正在关注本指南http://spring.io/guides/gs/messaging-stomp-websocket/,但我没有使用简单的消息代理,而是尝试使用 stomp 代理中继

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.enableStompBrokerRelay("/topic").setRelayHost("stomp://localhost").setRelayPort(61612);
    registry.setApplicationDestinationPrefixes("/app");
}

我正在尝试,但我的控制台一直显示连接失败

2016-02-26 01:38:05.786 INFO 3584 --- [main] o.s.m.s.s.StompBrokerRelayMessageHandler :将“系统”会话连接到 stomp://localhost:61612

2016-02-26 01:38:05.942 INFO 3584 --- [eactor-tcp-io-1] r.io.net.impl.netty.tcp.NettyTcpClient:无法连接到 stomp://localhost :61612。尝试在 5000 毫秒内重新连接。

2016-02-26 01:38:05.957 INFO 3584 --- [main] o.s.m.s.s.StompBrokerRelayMessageHandler :已启动。

2016-02-26 01:38:06.025 INFO 3584 --- [main] s.b.c.e.t.TomcatEmbeddedServletContainer:Tomcat 在端口:8052 (http) 上启动

2016-02-26 01:38:06.025 INFO 3584 --- [main] main.java.test.TestApplication:在 9.419 秒内启动了 TestApplication(JVM 运行 15.121)

2016-02-26 01:38:11.022 INFO 3584 --- [eactor-tcp-io-2] r.io.net.impl.netty.tcp.NettyTcpClient:无法连接到 stomp://localhost :61612。尝试在 5000 毫秒内重新连接。

2016-02-26 01:38:16.008 INFO 3584 --- [eactor-tcp-io-3] r.io.net.impl.netty.tcp.NettyTcpClient:无法连接到 stomp://localhost :61612。尝试在 5000 毫秒内重新连接。

我的activemq.xml是默认的,除了这个:

<transportConnectors>
        <transportConnector name="stomp" uri="stomp://localhost:61612"/>
 </transportConnectors>

ActiveMQ 启动没有问题,因为我可以连接到http://localhost:8161/admin 的管理页面。

这是我的 maven pom.xml,以防有人发现我可能使用了错误的依赖项

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.test.program</groupId>
<artifactId>testapp</artifactId>
<version>0.1.0</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.3.2.RELEASE</version>
</parent>


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

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

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
    </dependency>

    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20140107</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-core</artifactId>
        <version>3.1.5</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.1.5</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>3.1.5</version>
    </dependency>


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

    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-net</artifactId>
        <version>2.0.7.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-transport</artifactId>
        <version>4.0.34.Final</version>
    </dependency>

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-transport-native-epoll</artifactId>
        <version>4.0.34.Final</version>
    </dependency>

</dependencies>

<properties>
    <java.version>1.8</java.version>
</properties>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-milestone</id>
        <url>https://repo.spring.io/libs-release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>

</repositories>


<pluginRepositories>
    <pluginRepository>
        <id>spring-milestone</id>
        <url>https://repo.spring.io/libs-release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

【问题讨论】:

  • 您是否检查了 stomp 传输连接器是否已启动并运行,activemq 管理页面可能可以访问,请检查传输连接器
  • 有什么特殊的检查方法吗?据我所知,当我启动activemq时,它不会在控制台中显示任何地址绑定错误。

标签: spring activemq


【解决方案1】:

问题解决了。

我只需要删除“stomp://”前缀。由于spring配置方法暗示它是一个stomp中继,我不需要自己添加前缀。如果在默认的activemq安装中设置了也需要输入用户名和密码。

@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
    registry.enableStompBrokerRelay("/topic")
        .setRelayHost("127.0.0.1")
        .setRelayPort(61613)
        .setClientLogin("system")
        .setClientPasscode("password")
    registry.setApplicationDestinationPrefixes("/app");

}

【讨论】:

    【解决方案2】:

    如下所示更改configureMessageBroker

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-13
      • 2015-07-08
      • 2014-08-21
      • 2015-10-14
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      相关资源
      最近更新 更多