繁体   English   中英

Spring Boot和嵌入式ActiveMQ主机配置

[英]Spring boot and embedded activemq host configuration

我有一个spring boot应用程序,它会收到来自客户端的Websocket主题订阅,该订阅将路由到我的嵌入式activemq代理。

我的代码来启动我的嵌入式activemq代理

@SpringBootApplication
public class RttApplication {

public static void main(String[] args) throws Exception {
    ConfigurableApplicationContext ctx = SpringApplication.run(RttApplication.class, args);
    BrokerService brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    brokerService.addConnector("vm://localhost:0");
    brokerService.setBrokerName("event");
    brokerService.start();
}

}

我的Spring Broker中继配置类

@Configuration
@EnableWebSocketMessageBroker
public class MessageBrokerConfigurer extends AbstractWebSocketMessageBrokerConfigurer {
   @Override
   public void registerStompEndpoints(StompEndpointRegistry registry) {
       registry.addEndpoint("/event").withSockJS();
   }

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

但是在我启动应用程序时就显示了这一点

2016-02-25 15:44:34.678信息7604 --- [main] oaactivemq.broker.TransportConnector:连接器vm:// localhost:0已启动

2016-02-25 15:44:34.694信息7604-[[main] o.apache.activemq.broker.BrokerService:Apache ActiveMQ 5.7.0(事件,ID:PC13082-53189-1456386274543-0:1)

2016-02-25 15:44:34.694信息7604 --- [main] o.apache.activemq.broker.BrokerService:有关帮助或更多信息,请参见: http ://activemq.apache.org

2016-02-25 15:44:39.532信息7604 --- [eactor-tcp-io-2] r.io.net.impl.netty.tcp.NettyTcpClient:无法连接到vm:// localhost:0。 尝试在5000毫秒内重新连接。

问题已解决,因为Spring配置器方法暗示它是一个踩脚代理中继,必须通过踩脚协议进行。

同样,显然不需要传输协议前缀。 如果在默认的activemq安装中设置了用户名和密码,我还需要输入用户名和密码。 但这是在启动独立的ActiveMQ之后完成的,我实际上正在寻找的是嵌入式解决方案。

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

}

UPDATE

针对Deinum的上述评论之一。 我还尝试仅在spring boot应用程序的application.properties中设置以下内容:

spring.activemq.broker-url=stomp://127.0.0.1:61614
spring.activemq.user=system
spring.activemq.password=password

但是该控制台没有显示ActiveMQ正在启动的迹象,也无法通过上述脚踏代理中继配置连接到该控制台。 我最终创建了一个spring配置类,它现在可以工作:

//@Configuration
public class TestBrokerConfig {

@Bean( initMethod = "start", destroyMethod = "stop" )
public BrokerService broker() throws Exception {
    final BrokerService broker = new BrokerService();               
    broker.addConnector( "stomp://localhost:61614" );

    broker.setPersistent( false );
    broker.setShutdownHooks( Collections.< Runnable >singletonList( new SpringContextHook() ) );
    final ManagementContext managementContext = new ManagementContext();
    managementContext.setCreateConnector( true );
    broker.setManagementContext( managementContext );

    return broker;
}
}

暂无
暂无

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

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