I have configured my rabbit properties via application.yaml and spring configurationProperties. Thus, when I configure exchanges, queues and bindings, I can use the getters of my properties
@Bean Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(properties.getQueue());
}
@Bean Queue queue() {
return new Queue(properties.getQueue(), true);
}
@Bean TopicExchange exchange() {
return new TopicExchange(properties.getExchange());
}
However, when I configure a @RabbitListener to log the messages on from the queue, I have to use the full properties name like
@RabbitListener(queues = "${some.long.path.to.the.queue.name}")
public void onMessage(
final Message message, final Channel channel) throws Exception {
log.info("receiving message: {}#{}", message, channel);
}
I want to avoid this error prone hard coded String and refer to the configurationProperties bean like:
@RabbitListener(queues = "${properties.getQueue()}")
I had a similar issue once with @EventListener where using a bean reference "@bean.method()" helped, but it does not work here, the bean expression is just interpreted as queue name, which fails because a queue namde "@bean...." does not exist.
Is it possible to use ConfigurationProperty-Beans for RabbitListener queue configuration?