我读过几本 examples关于 spring boot 中的 jms 支持。
通常发送方、接收方和 active-mq(实际上它可以是任何其他 jms 兼容的消息代理)位于同一应用程序中。
我知道我可以使用独立的 Activity mq 和 use propertie小号:
spring.activemq.broker-url=tcp://192.168.1.210:9876
spring.activemq.user=admin
spring.activemq.password=secret
但我想有 2 个应用程序:
1- 发送者(从嵌入的接收者连接到 jms 并在那里发送消息)
2-receiver(上应用和内嵌activemq)
可能吗?
最佳答案
只需在您的应用程序中添加一个 BrokerService
bean:
@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
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-kahadb-store</artifactId>
</dependency>
关于java - 是否可以从另一个应用程序(在单独的进程中启动)连接到 spring boot 嵌入式 ActiveMQ 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48504265/