【问题标题】:Wildcard routing not working in ActiveMQ Artemis通配符路由在 ActiveMQ Artemis 中不起作用
【发布时间】:2020-01-08 04:49:54
【问题描述】:

我使用 Apache Artemis 作为消息总线和 JMS 来监听消息并将消息发送到消息总线。我有一个用例,我想收听与模式匹配的所有队列(例如主题以 xxxx 开头)。根据我的探索,我们可以使用通配符路由来做到这一点。 http://activemq.apache.org/wildcards.html

我在 broker.xml 中添加了以下内容

<wildcard-addresses>
    <routing-enabled>true</routing-enabled>
</wildcard-addresses>

我正在使用以下代码向队列发送消息:

@Component
@EnableJms
public class Producer {
    @Autowired
    JmsTemplate jmsTemplate;

    @Value("address.client1")
    String destinationQueue;

    public void send(String msg){
        jmsTemplate.convertAndSend(destinationQueue, msg);
    }

}

下面是我的监听器,它应该监听所有以 address 开头的队列。

@Component
public class Consumer { 

    @JmsListener(destination = "address.>")
    public void receive(Message message){
        if(message.getPayload() instanceof String){
            System.out.println("Recieved Message: " + message.getPayload().toString());
        }else {
            System.err.println("Message Type Unkown !");
        }
    }
}

但我无法接收我们从发送方发送到接收方代码的消息。谁能帮我解决这个问题?

【问题讨论】:

  • 您已禁用路由,但您想知道为什么它不起作用? &lt;routing-enabled&gt;false&lt;/routing-enabled&gt;
  • 对不起,我在问题中的错误
  • 我有它是真的

标签: java spring jms activemq-artemis


【解决方案1】:

您在问题中链接的文档适用于 ActiveMQ 5.x,而不是 ActiveMQ Artemis。通配符的 ActiveMQ Artemis 文档是 here

您的消费者的问题是您使用了错误的语法。它正在使用address.&gt;。您可以在 Artemis 中更改通配符语法配置,例如:

<wildcard-addresses>
   <routing-enabled>true</routing-enabled>
   <any-words>&gt;</any-words>
</wildcard-addresses>

或者您可以使用默认 Artemis 配置中功能等效的语法,即address.#

【讨论】:

    猜你喜欢
    • 2017-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 2015-07-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    相关资源
    最近更新 更多