如何在Spring Boot中将不同的目标动态添加到JMSListener注释? [英] How to add different destination dynamically to JMSListener Annotation in Spring boot?

查看:327
本文介绍了如何在Spring Boot中将不同的目标动态添加到JMSListener注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个从Azure服务总线读取消息的应用程序.该应用程序是使用Spring Boot,Spring jms和Qpid jms客户端创建的.我能够从Queue正确读取消息,而没有任何问题. PFB我用来阅读消息的代码.

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);
    }
}}

问题是我们对于不同的环境有不同的目的地,例如devtestingqatesting-qaproductiontesting-prod,所有这些值在不同的应用程序中均作为azure.queueName提供-(ENV).属性.我想将这些目标动态传递给JmsListener注释中的目标.当我尝试使用

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;

并将dest传递给@JmsListener(destination = dest)

我收到The value for annotation attribute JmsListener.destination must be a constant expression错误.仔细检查了此错误后,我发现我们无法将动态值传递给注释.请帮助我如何解决此问题或其他解决方案.

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.

推荐答案

使用

destination="${azure.queueName}"

即将占位符直接放在注释中.

i.e. put the placeholder in the annotation directly.

这篇关于如何在Spring Boot中将不同的目标动态添加到JMSListener注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆