Use Property Placeholder with Spring AMQP @SendTo Annotation

混江龙づ霸主 提交于 2019-12-11 11:18:44

问题


I have the same problem mentioned in this unanswered question: Spring Cloud AWS SQS SendTo annotation with property placeholder

But, I'm asking it again more succinctly in hopes that it will be answered this time.

As mentioned in the question I had referred to, this issue: https://github.com/spring-cloud/spring-cloud-aws/issues/65 seems to indicated that the @SentTo annotation should support property placeholders.

However, when it comes to the @SendTo annotation, the Spring AMQP documentation only talks about SpEL (bean evaluation '#{...}' and runtime '!{...}'), but doesn't mention property placeholders.

When I tried using @SendTo("${my.reply.routing.key}") or @SendTo("${my-exchange}/${my.reply.routing.key}"), is being interpreted literally and isn't being properly interpolated.

Are there any workarounds for me to use property placeholder in this case?


回答1:


It only supports expressions; you can work around it, though; such as by using a bean reference:

@SpringBootApplication
public class So51620793Application {

    public static void main(String[] args) {
        SpringApplication.run(So51620793Application.class, args);
    }

    @RabbitListener(queues = "foo")
    @SendTo("#{@sendTo}")
    public String listen(Message in) {
        System.out.println(in);
        return new String(in.getBody()).toUpperCase();
    }

    @Bean
    public String sendTo(@Value("${foo.bar}") String sendTo) {
        return sendTo;
    }

}

I am not familiar with the AWS code; each project rolls its own for this annotation.



来源:https://stackoverflow.com/questions/51620793/use-property-placeholder-with-spring-amqp-sendto-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!