避免使用 Spring 引导微服务实例多次侦听 ActiveMQ 主题

Avoid multiple listens to ActiveMQ topic with Spring Boot microservice instances

我们已经将我们的 ActiveMQ 消息代理配置为一个 Spring 引导项目,还有另一个 Spring 引导应用程序(我们称之为 service-A),它有一个监听器配置为监听一些使用 @JmsListener 注释的主题。这是一个 Spring 云微服务应用程序。

问题:

是否可以 运行 集群模式或类似的微服务?我也检查了 ActiveMQ virtual destinations 但不太确定这是否是问题的解决方案。

我们也想到了一种方法,我们可以从多个实例中决定谁是领导节点,但这是最后的手段,我们正在寻找一种更简洁的方法。

欢迎指点、参考。

你真正想要的是shared topic subscription which was added in JMS 2. Unfortunately ActiveMQ 5.x doesn't support JMS 2. However, ActiveMQ Artemis

ActiveMQ Artemis 是 ActiveMQ 的下一代代理。它支持 most of the same features as ActiveMQ 5.x (including full support for OpenWire clients) as well as many other features that 5.x doesn't support (e.g. JMS 2, shared-nothing high-availability using replication, last-value queues, ring queues, metrics plugins for integration with tools like Prometheus, duplicate message detection,等等)。此外,ActiveMQ Artemis 建立在高性能、非阻塞核心之上,这意味着可扩展性也更好。