0
votes

I am using Apache Artemis as the message bus and JMS to listen and send messages to the message bus. I have a use case where I want to listen to all queues that matches a pattern(Eg the topic starts with xxxx). According to what I have explored we can use wildcard routing to do that. http://activemq.apache.org/wildcards.html

I have put the following in my broker.xml

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

I am using the following code to send a message to a queue:

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

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

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

}

Below is my Listener that should listen to all the queues that starts with 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 !");
        }
    }
}

But I am not able to receive the message that we sent from the sender to the receiver code. Can anyone help me on this?

2
You've disabled the routing and you're wondering why it doesn't work? <routing-enabled>false</routing-enabled>Kayaman
Sorry my mistake in the questionRitwik Bhar
I have it has trueRitwik Bhar

2 Answers

1
votes

The documentation you linked in your question is for ActiveMQ 5.x, not ActiveMQ Artemis. The ActiveMQ Artemis documentation for wildcards is here.

The problem with your consumer is that you're using the wrong syntax. It is using address.>. You can either change the wildcard syntax configuration in Artemis, e.g.:

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

Or you can use the functionally equivalent syntax from the default Artemis configuration, i.e. address.#.

0
votes

I am having the same problem with Artemis 2.17.0. I used Spring boot Artemis dependency to send messages to multiple queues via:

jmsTemplate.convertAndSend(destination, message)

I am sending the message to 3 different queues as:

  • queue.test1.event
  • queue.test2.event
  • queue.test2.event

on the listener side, I am using the wildcard to read from all of the queues, like:

    @JmsListener(destination = "queue.#")
    public void receiveMessage(String event) {
      //....
    }

But I am not getting anything. The web console shows I have 4 queues (3 mentioned above with another one as "queue.#") and the WildcardRoutingEnabled is set to true as well.

This official Artemis documentation explained the Artemis wildcard pattern and I am following it. Don't know why it doesn't work.

PS: I have used the ActiveMQ wildcard pattern with ActiveMQ before and it worked perfectly with Spring boot ActiveMQ dependency(used this listener: @JmsListener(destination = "queue.>"))