5

In my Spring Boot application I have configured following JMS Listener:

@Component
public class Consumer {
    
    @JmsListener(destination = "image.index.queue")
    public void receiveQueue(IndexRequest indexRequest) {
        ...
    }   
}

How to supply destination name image.index.queue from configuration (e.g. application.properties) instead of a hardcoded value?

xlm
  • 6,854
  • 14
  • 53
  • 55
alexanoid
  • 24,051
  • 54
  • 210
  • 410

2 Answers2

6
import org.springframework.beans.factory.annotation.Value;

@JmsListener(destination = @Value("${jmx.image.index.queue}")
public void receiveQueue(IndexRequest indexRequest) {
    ...
}

And in your properties file

jmx.image.index.queue=image.index.queue
techtabu
  • 23,241
  • 3
  • 25
  • 34
0

You need to indicate to Spring that it's a placeholder value, so instead of:

@JmsListener(destination = "image.index.queue")

Use:

@JmsListener(destination = "${image.index.queue}")

If needed, you can also use SpEL but this shouldn't be necessary if using application.properties. E.g.:

@JmsListener(destination = "#{systemProperties['image.index.queue']}")

Verified as of Spring Boot 2.0.0.RELEASE

xlm
  • 6,854
  • 14
  • 53
  • 55