Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring引导和嵌入式activemq主机配置_Java_Spring Boot_Activemq - Fatal编程技术网

Java Spring引导和嵌入式activemq主机配置

Java Spring引导和嵌入式activemq主机配置,java,spring-boot,activemq,Java,Spring Boot,Activemq,我有一个spring引导应用程序,它从客户端接收stomp over websocket主题订阅,这些订阅将被路由到我的嵌入式activemq代理 启动嵌入式activemq代理的代码 @SpringBootApplication public class RttApplication { public static void main(String[] args) throws Exception { ConfigurableApplicationContext ctx = Spri

我有一个spring引导应用程序,它从客户端接收stomp over 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();
}

}
我的SpringBroker中继配置类

@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---[主页] o、 a.activemq.broker.TransportConnector:Connector vm://localhost:0 开始

2016-02-25 15:44:34.694信息7604---[主页] o、 apache.activemq.broker.BrokerService:apache activemq 5.7.0 (事件,ID:PC13082-53189-1456386274543-0:1)已开始

2016-02-25 15:44:34.694信息7604---[主页] o、 apache.activemq.broker.BrokerService:获取帮助或更多信息 有关资料请参阅:

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


问题解决了,因为Spring配置器方法暗示它是一个stomp代理中继,所以它必须通过stomp协议

此外,显然不需要传输协议前缀。如果在默认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");

}
更新

作为对Deinum上述评论之一的回应。我还尝试在我的application.properties中简单地设置以下内容:

spring.activemq.broker-url=stomp://127.0.0.1:61614
spring.activemq.user=system
spring.activemq.password=password
但是控制台没有显示ActiveMQ已启动的迹象,我也无法通过上面发布的stomp broker中继配置连接到它。我最终创建了一个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;
}
}
/@配置
公共类TestBrokerConfig{
@Bean(initMethod=“开始”,destromethod=“停止”)
public BrokerService broker()引发异常{
final BrokerService broker=新BrokerService();
broker.addConnector(“stomp://localhost:61614" );
broker.setPersistent(false);
setShutdownHooks(Collections.singletonList(newspringcontexthook());
最终ManagementContext ManagementContext=新的ManagementContext();
managementContext.setCreateConnector(true);
broker.setManagementContext(managementContext);
回报经纪人;
}
}

启动应用程序后,您将启动代理。那是行不通的。还有,你为什么不让Spring来启动代理呢?只需向
应用程序添加几个属性。属性
就完成了。我可以专门向应用程序添加哪些属性。属性?有没有参考指南指向这一点?不管怎样,我想我找到了:。示例中有一部分指向activemq配置,不确定它有多完整。请检查这对您有很大帮助。感谢Praveen,我以前在搜索google时看到过这一点,但当它说JMS消息时,我被甩了。基本上,我的客户机将通过STOMP协议连接到我的spring应用程序。也许JMS是代理和我的主应用程序之间使用的格式,然后作为stomp消息路由回我的客户机?希望有人能帮我区分这一点。我有一个解决方案,使用您在底部定义的代理服务bean,但我可以连接到它,而无需来自指向该代理的客户端应用程序的凭据。我试图找出如何公开spring boot嵌入式activemq,但要用用户名和密码(最终是SSL,但这是下一步)来保护它。