从另一个应用程序(在分离的进程中启动)连接到Spring Boot嵌入式ActiveMq实例是否可行? [英] Is it posiible to connect to spring boot embedded ActiveMq instance from another application(started in separated process)?
问题描述
我已经阅读了几个有关春季启动中jms支持的示例。
I've read several examples about jms support in spring boot.
通常发送方,接收方和active-mq(实际上它可以是任何其他jms兼容的消息代理)位于同一个应用程序中。
and usually sender, receiver and active-mq(actually it can be any other jms compatible message broker) locates within the same application.
我知道我可以使用独立的活动mq和使用属性 s:
I know that I can use stand alone active mq and use properties:
spring.activemq.broker-url=tcp://192.168.1.210:9876
spring.activemq.user=admin
spring.activemq.password=secret
但我希望有2个申请:
1-发送者(从嵌入式接收器连接到jms并在那里发送消息)
2接收器(up应用程序和嵌入式activemq)
1- sender (connects to jms from receiver embedded and sends messages there)
2-receiver (up application and embedded activemq)
它是否可用?
推荐答案
只需添加一个 Broker服务
bean到您的应用程序:
Just add a BrokerService
bean to your application:
@SpringBootApplication
public class So48504265Application {
public static void main(String[] args) {
SpringApplication.run(So48504265Application.class, args);
}
@Bean
public BrokerService broker() throws Exception {
BrokerService broker = new BrokerService();
broker.addConnector("tcp://localhost:61616);
return broker;
}
@Bean
public ApplicationRunner runner(JmsTemplate template) {
return args -> template.convertAndSend("foo", "AMessage");
}
@JmsListener(destination = "foo")
public void listen(String in) {
System.out.println(in);
}
}
和
spring.activemq.broker-url=tcp://localhost:61616
并将其添加到您的pom
and add this to your pom
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-kahadb-store</artifactId>
</dependency>
这篇关于从另一个应用程序(在分离的进程中启动)连接到Spring Boot嵌入式ActiveMq实例是否可行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!