避免使用 Spring Boot 微服务实例多次监听 ActiveMQ 主题 [英] Avoid multiple listens to ActiveMQ topic with Spring Boot microservice instances

查看:90
本文介绍了避免使用 Spring Boot 微服务实例多次监听 ActiveMQ 主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We have configured our ActiveMQ message broker as a Spring Boot project and there's another Spring Boot application (let's call it service-A) that has a listener configured to listen to some topics using @JmsListener annotation. It's a Spring Cloud microservice appilcation.

问题:

  • service-A 有可能运行多个实例.
  • 如果我们有 2 个实例在运行,那么任何关于主题的消息都会被监听两次.
  • 我们如何避免每个实例都在听主题?
  • 无论service-A 实例的数量如何,我们都希望确保主题只被收听一次.
  • It is possible that service-A can have multiple instances running.
  • If we have 2 instances running, then any message coming on topic gets listened to twice.
  • How can we avoid every instance listening to the topic?
  • We want to make sure that the topic is listened to only once no matte the number of service-A instances.

是否可以在集群模式或类似模式下运行微服务?我还查看了 ActiveMQ 虚拟目的地,但不太确定这是否是问题的解决方案.

Is it possible to run the microservice in a cluster mode or something similar? I also checked out ActiveMQ virtual destinations but not too sure if that's the solution to the problem.

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

We have also thought of an approach where we can decide who's the leader node from the multiple instances, but that's the last resort and we are looking for a cleaner approach.

任何有用的指针,欢迎参考.

Any useful pointers, references are welcome.

推荐答案

您真正想要的是 共享主题订阅.不幸的是,ActiveMQ 5.x 不支持 JMS 2.但是,ActiveMQ Artemis 确实如此.

What you really want is a shared topic subscription which was added in JMS 2. Unfortunately ActiveMQ 5.x doesn't support JMS 2. However, ActiveMQ Artemis does.

ActiveMQ Artemis 是 ActiveMQ 的下一代代理.它支持 大多数与 ActiveMQ 5.x 相同的功能(包括对 OpenWire 的完全支持客户端)以及 5.x 不支持的许多其他功能(例如 JMS 2、shared-nothing 高可用性使用复制最后值队列环形队列指标插件a> 用于与 Prometheus 等工具集成,重复消息检测 等).此外,ActiveMQ Artemis 建立在高性能、无阻塞的内核之上,这意味着可扩展性也更好.

ActiveMQ Artemis is the next generation broker from ActiveMQ. It supports 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, etc.). Furthermore, ActiveMQ Artemis is built on a high-performance, non-blocking core which means scalability is much better as well.

这篇关于避免使用 Spring Boot 微服务实例多次监听 ActiveMQ 主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆