Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rabbit listener annotation get queue name from yaml

I currently have my rabbit listener annotation set as:

@RabbitListener(queues = "my-queue")

Is it not possible to pull in the queue name from my yaml file. The reason I want to do this, is so that I can change my queue to a test queue for my integration test, simply by changing the queue name in the yaml file. It appears the annotation must accept a constant string, is there a way round this? Thanks,

like image 491
helpme7766 Avatar asked Sep 08 '17 23:09

helpme7766


1 Answers

Yes, it is called properties place holder and can be done like this:

@RabbitListener(queues = "${myQueue.property}")

Where that myQueue.property is exactly declared in your yaml.

https://docs.spring.io/spring-amqp/docs/1.7.3.RELEASE/reference/html/_reference.html#async-annotation-driven

The argument name, value, and type can be property placeholders (${...}) or SpEL expressions (#{...}). The name must resolve to a String; the expression for type must resolve to a Class or the fully-qualified name of a class. The value must resolve to something that can be converted by the DefaultConversionService to the type (such as the x-message-ttl in the above example).

like image 143
Artem Bilan Avatar answered Nov 17 '22 10:11

Artem Bilan