如果您的2个Spring Boot应用程序位于同一jvm上,则只需 添加以下两个应用程序之一的application.properties:
spring.activemq.broker-url=vm://localhost
当Spring
Boot检测到ActiveMQ在类路径上可用时,它也可以配置ConnectionFactory。如果存在代理,则将自动启动并配置嵌入式代理(只要未通过配置指定代理URL)。
如果您的2个Spring Boot应用程序位于2个不同的jvm上:在一个spring boot应用程序中,您需要具备:
在pom.xml中
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-activemq --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-activemq</artifactId> <version>1.4.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> </dependency>
在第二个:
在application.properties中
spring.activemq.broker-url=tcp://localhost:61616
在pom.xml中
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId></dependency>
如果您有2个jvm,每个应用程序1个,默认情况下,spring boot将仅使用vm连接器配置AMQ,在第一个应用程序中,您需要添加tcp连接器,如下所示:
@Bean(initMethod = "start", destroyMethod = "stop")public BrokerService broker() throws Exception { final BrokerService broker = new BrokerService(); broker.addConnector("tcp://localhost:61616"); broker.addConnector("vm://localhost"); broker.setPersistent(false); return broker;}


