【问题标题】:How to configure ActiveMQ exclusive consumer with Spring boot app如何使用 Spring Boot 应用配置 ActiveMQ 独占消费者
【发布时间】:2019-05-04 18:01:30
【问题描述】:

我想用 Spring boot 为 ActiveMQ 配置独占消费者 用java配置很容易

 queue = new ActiveMQQueue("TEST.QUEUE?consumer.exclusive=true");
 consumer = session.createConsumer(queue);

但是使用 Spring boot,监听器的配置如下。

 @JmsListener(destination = "TEST.QUEUE", containerFactory = "myFactory")
 public void receiveMessage(Object message) throws Exception {
    ......
 }

现在,如何让这个独家消费者?下面的工作吗?

 @JmsListener(destination = "TEST.QUEUE?consumer.exclusive=true", containerFactory = "myFactory")
 public void receiveMessage(Object message) throws Exception {
    ......
 }

【问题讨论】:

  • 你能解决这个问题吗?我正在尝试做同样的事情

标签: java spring spring-boot activemq


【解决方案1】:

是的,它是这样工作的。

只需在org.apache.activemq.command.ActiveMQQueue 构造函数中设置一个断点,然后在调试模式下运行您的应用程序。
你会看到 Spring Boot 正在调用 new ActiveMQQueue("TEST.QUEUE?consumer.exclusive=true") 对应 ActiveMQ 官方文档: https://activemq.apache.org/exclusive-consumer

此外,您可以转到 ActiveMQ 管理员并浏览此队列的活动消费者:您现在将看到您的消费者的独占标志设置为 true。

【讨论】:

    猜你喜欢
    • 2015-01-28
    • 2018-03-14
    • 2018-05-22
    • 2015-01-28
    • 2018-12-18
    • 2018-12-22
    • 2019-04-30
    • 1970-01-01
    • 2015-07-27
    相关资源
    最近更新 更多