我有2个弹簧启动应用程序。每个应用程序都嵌入了活动的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>
如何解决此问题(启动时挂起的应用程序)?
答案 0 :(得分:3)
您的配置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;
}