Spring boot + ActiveMQ + stomp broker relay无法连接

时间:2016-02-25 18:01:40

标签: spring activemq

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

@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:将“system”会话连接到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“&GT;     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>

2 个答案:

答案 0 :(得分:0)

问题解决了。

我只需要删除“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");

}

答案 1 :(得分:0)

如下所示更改configureMessageBroker

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