编程语言
首页 > 编程语言> > java – 无法在不同的Spring启动应用程序中的不同端口上启动2个嵌入式active-mq

java – 无法在不同的Spring启动应用程序中的不同端口上启动2个嵌入式active-mq

作者:互联网

我有2个spring-boot应用程序.每个应用程序都嵌入了活动的mq代理.

我需要在同一台PC上同时运行2个应用程序,但它现在不起作用.第一个应用始终成功启动:

2018-02-02 11:48:20.095  INFO 7660 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@53045c6c: startup date [Fri Feb 02 11:48:20 MSK 2018]; root of context hierarchy
2018-02-02 11:48:20.923  INFO 7660 --- [  JMX connector] o.a.a.broker.jmx.ManagementContext       : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:7777/jmxrmi
2018-02-02 11:48:20.923  INFO 7660 --- [           main] o.apache.activemq.broker.BrokerService   : Using Persistence Adapter: KahaDBPersistenceAdapter[D:\work\arbitrage_robot\root\activemq-data\localhost\KahaDB]
2018-02-02 11:48:21.231  INFO 7660 --- [           main] o.a.a.store.kahadb.MessageDatabase       : KahaDB is version 6
2018-02-02 11:48:21.260  INFO 7660 --- [           main] o.a.a.store.kahadb.plist.PListStoreImpl  : PListStore:[D:\work\arbitrage_robot\root\activemq-data\localhost\tmp_storage] started
2018-02-02 11:48:21.395  INFO 7660 --- [           main] o.apache.activemq.broker.BrokerService   : Apache ActiveMQ 5.15.2 (localhost, ID:ntkachev-60101-1517561301266-0:1) is starting
2018-02-02 11:48:21.441  INFO 7660 --- [           main] o.a.a.t.TransportServerThreadSupport     : Listening for connections at: tcp://127.0.0.1:61617?broker.persistent=false
2018-02-02 11:48:21.442  INFO 7660 --- [           main] o.a.activemq.broker.TransportConnector   : Connector tcp://127.0.0.1:61617?broker.persistent=false started
2018-02-02 11:48:21.442  INFO 7660 --- [           main] o.apache.activemq.broker.BrokerService   : Apache ActiveMQ 5.15.2 (localhost, ID:ntkachev-60101-1517561301266-0:1) started
2018-02-02 11:48:21.442  INFO 7660 --- [           main] o.apache.activemq.broker.BrokerService   : For help or more information please see: http://activemq.apache.org
2018-02-02 11:48:23.002  INFO 7660 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-02-02 11:48:23.021  INFO 7660 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 2147483647
2018-02-02 11:48:23.024  INFO 7660 --- [           main] o.a.activemq.broker.TransportConnector   : Connector vm://localhost started
2018-02-02 11:48:23.051  INFO 7660 --- [           main] pack.Application                 : Started Application in 3.337 seconds (JVM running for 3.922)

但第二次冻结并打印:

2018-02-02 11:48:30.450  INFO 17008 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@53045c6c: startup date [Fri Feb 02 11:48:30 MSK 2018]; root of context hierarchy
2018-02-02 11:48:31.296  INFO 17008 --- [           main] o.apache.activemq.broker.BrokerService   : Using Persistence Adapter: KahaDBPersistenceAdapter[D:\work\app\root\activemq-data\localhost\KahaDB]
2018-02-02 11:48:31.297  INFO 17008 --- [  JMX connector] o.a.a.broker.jmx.ManagementContext       : JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
2018-02-02 11:48:31.300  INFO 17008 --- [           main] o.a.activemq.store.SharedFileLocker      : Database activemq-data\localhost\KahaDB\lock is locked by another server. This broker is now in slave mode waiting a lock to be acquired

两个应用程序具有大致相同的配置:

@SpringBootApplication
public class Application {

  @Bean
  public BrokerService broker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.addConnector("tcp://localhost:61616?broker.persistent=false");
    return broker;
  }

  @JmsListener(destination = "robotCommand")
  public void listen(String in) {
      System.out.println(in);
  }

以及依赖关系:

   <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-kahadb-store</artifactId>
        <version>5.15.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-broker</artifactId>
        <version>5.15.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-activemq</artifactId>
        <version>1.5.10.RELEASE</version>
    </dependency>

我该如何解决这个问题(启动时挂起的应用程序)?

解决方法:

你的config broker.addConnector(“tcp:// localhost:61616?broker.persistent = false”);如果使用ActiveMQConnectionFactory,http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html#HowdoIembedaBrokerinsideaConnection-UsingActiveMQConnectionFactory创建代理,则可以执行此操作

Using ActiveMQConnectionFactory
An embedded broker can also be created using an ActiveMQConnectionFactory and using a vm connector as a uri. e.g.
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");

尝试

 @Bean
  public BrokerService broker() throws Exception {
    BrokerService broker = new BrokerService();
    broker.addConnector("tcp://localhost:61616");
    broker.setPersistent(false);
    return broker;
  }

标签:java,spring,spring-boot,activemq,spring-jms
来源: https://codeday.me/bug/20190926/1819715.html