Search code examples
spring-bootrabbitmqspring-rabbit

Is possible to use regex with @RabbitListener queues?


I haven't found anything similar, so I ask here in case someone knows if it possible.

The scenario is simple, suposse a project using Spring Boot and RabbitMQ; to listen queues you have something like this:

@RabbitListener(queues = "example-queue")
public void receiveQueueMessage(String message) {
    System.out.println("[x] Received: '" + message + "'");
}

So, is there a way to use regex in a way similar to this?:

@RabbitListener(queues = \queue\)
public void receiveQueueMessage(String message) {
    System.out.println("[x] Received: '" + message + "'");
}

Thanks in advance.


Solution

  • No; RabbitMQ does not support RegEx for queue names.

    You can use the management plugin's REST API to get a list of queues and add them to the container manually (container.addQueueNames(...)).

    Using a Direct message listener container is more efficient for that; see Choosing a Container.