Adding Dynamic Number of Listeners(Spring JMS)

You can’t do it with annotated @JmsListeners but you can register each listener programmatically by extending JmsListenerConfigurer as described in the reference documentation.

EDIT

Since you are injecting the property as an array…

@Value("${InTopics}")
private String[] inTopics;

Spring will split up the list an create an array based on the number of queues in the list.

You can then iterate over the array in JmsListenerConfigurer.configureJmsListeners() and create an endpoint for each element in the array – you don’t need to know ahead of time how big the array is.

for (String inTopic : inTopics) {
    ...
}

Leave a Comment