Reputation: 503
I working on an application which reads message from Azure service bus. This application was created using spring boot, Spring jms and Qpid jms client. I am able to read the message properly from Queue without any issues. PFB My code which I am using to read message.
@Service
public class QueueReceiver {
@JmsListener(destination = "testing")
public void onMessage(String message) {
if (null != message) {
System.out.println("Received message from Queue: " + message);
}
}}
Issue is we have different destinations for different environemnts, like testing
for dev
, testing-qa
for qa
and testing-prod
for production
, all these values are provided as azure.queueName
in different application-(ENV).proerpties respectively. I want to pass these destinations dynamically to the destination in JmsListener Annotation. When i try using
@Value("${azure.queueName}")
private String dest;
and passing dest to annotation like @JmsListener(destination = dest)
I am getting The value for annotation attribute JmsListener.destination must be a constant expression
Error. After googling with this Error i found that we cannot pass dynamic value to Annotation. Please help me how to resolve this issue or any other solution for this.
Upvotes: 1
Views: 8742
Reputation: 1070
You can use a dynamic name as defined in the application.properties file.For Example:
@JmsListener(destination = "${queue.name}")
Since you can't access any class variables here so this is the best option available.
Upvotes: 1
Reputation: 174554
Use
destination="${azure.queueName}"
i.e. put the placeholder in the annotation directly.
Upvotes: 13