1

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?

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
nemo
  • 1,504
  • 3
  • 21
  • 41

1 Answers1

2

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.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • AWS wasn't a concern for me. It was only for the poster of the original question. Although it would have been great to use property placeholders like I can with the `@RabbitListner` and `@Queue` annotations, your workaround will work for me. Thanks! – nemo Jul 31 '18 at 20:45
  • I have found that this can be used as well `@SendTo("#{environment['foo.bar']}"` – Artem Bilan Jul 31 '18 at 20:50
  • See the fix here: https://github.com/spring-projects/spring-amqp/pull/785 – Artem Bilan Jul 31 '18 at 20:53