I have application.properties file for spring app which contains some simple properties:
queue=my.test.q
in the java code i need to specify the queue to @RabbitListener:
@Component
public class Handler {
@RabbitListener(queues = "my.test.q")
public void handleMessage(Message message) {
...
}
that would work, but i want to pass parameter to the annotation, i've tried the following but none of them worked.
@Component
public class Handler {
@Value("${queue}")
private String queueName;
@RabbitListener(queues = @Value("${queue}") <-- not working
@RabbitListener(queues = queueName)) <--- not working
public void handleMessage(Message message) {
...
}
is it possible to that?
As you can see in the javadoc for the @RabbitListener annotation, the queues attribute is a table of Strings, so you cannot assign an annotation to it. You also cannot assign variables to annotation attributes at all in Java, as they are required to be compile constants.
I cannot test it right now, but the javadoc seems to suggest that this should work (note, that it says it may return SpEL expressions):
@RabbitListener(queues = "${queue}")
public void handleMessage(Message message) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With