繁体   English   中英

Spring 启动带有监听器的嵌入式 ActiveMQ Artemis

[英]Spring Boot Embedded ActiveMQ Artemis with listener

我正在尝试设置几个通过 ActiveMQ Artemis 进行通信的微型应用程序(作为一些新工具的演示)。 因为它只是一个演示,所以我试图让最终用户尽可能简单。 因此,我走的是 Spring Boot 现在拥有的嵌入式 Artemis 支持路线。

我有这个工作得很好。 但是,我不知道如何让它也监听本地端口,以便其他服务也可以连接到它。

基本上我想做的是:

  • 服务A
    • 作为服务启动的一部分启动嵌入式 Artemis
    • 允许此 Artemis 服务器被其他服务连接 <-- 这里的位
    • 有消费者在这个嵌入式 Artemis 上收听队列
  • 服务B
    • 连接到在服务 A 中运行的 Artemis <-- 这里有一点
    • 有一个 HTTP 端点,该端点将消息生成到该 Artemis 服务的队列中

我已经标记了我(还)无法弄清楚如何去做的部分。

作为参考,我的application.properties目前是这样的:

server.port=8082

spring.artemis.mode=EMBEDDED
spring.artemis.host=localhost
spring.artemis.port=61616

spring.artemis.embedded.enabled=true

spring.jms.template.default-destination=my-queue-1

logging.level.org.apache.activemq.audit.base=DEBUG
logging.level.org.apache.activemq.audit.message=DEBUG

有可能使这项工作吗? 还是我需要让人运行外部 Artemis 服务?

干杯

编辑。 阿耳emi弥斯不是必需的。 它只需要是一些异步消息传递平台。 如果可以使用 ActiveMQ Classic、RabbitMQ 或其他任何方式完成,那很好。

默认情况下,Spring 将只允许虚拟机内连接到 ActiveMQ Artemis 的嵌入式实例。 请参阅InVMAcceptorFactoryInVMAcceptorFactory的使用。

要更改此设置,您需要通过自定义ArtemisConfigurationCustomizer bean 添加一个新的 Acceptor 到您的 Artemis 配置,例如:

import org.springframework.boot.autoconfigure.jms.artemis.ArtemisConfigurationCustomizer;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ArtemisConfig implements ArtemisConfigurationCustomizer {
   @Override
   public void customize(org.apache.activemq.artemis.core.config.Configuration configuration) {
      configuration.addAcceptorConfiguration("remote", "tcp://0.0.0.0:61616");
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM