Spring Cloud AWS SQS SendTo annotation with property placeholder

匿名 (未验证) 提交于 2019-12-03 01:09:02

问题:

This issue suggests that the @SendTo annotation supports property placeholders, but I can't get it to work. Here's some simplified code snippets of what I'm trying to do (easier than trying to explain with words). I'm on spring-cloud-aws version 1.2.1.

This works:

@Component public class InputQueueListener {      @Value("${replyQueueProperty}")     private String replyQueue;      @Autowired     private QueueMessagingTemplate messagingTemplate;      @SqsListener(value = "${inputQueueProperty}", deletionPolicy = SqsMessageDeletionPolicy.NEVER)     private void receiveMessage(final Message message, final Acknowledgment acknowledgment, @Header("ApproximateReceiveCount") final int receiveCount) throws Exception {         final Reply reply = doStuff(message);          messagingTemplate.convertAndSend(replyQueue, reply);     } } 

And this works:

@Component public class InputQueueListener {      @SqsListener(value = "${inputQueueProperty}", deletionPolicy = SqsMessageDeletionPolicy.NEVER)     @SendTo("replyQueueActualName")     private Reply receiveMessage(final Message message, final Acknowledgment acknowledgment, @Header("ApproximateReceiveCount") final int receiveCount) throws Exception {         final Reply reply = doStuff(message);          return reply;     } } 

But this does not work:

@Component public class InputQueueListener {      @SqsListener(value = "${inputQueueProperty}", deletionPolicy = SqsMessageDeletionPolicy.NEVER)     @SendTo("${replyQueueProperty}")     private Reply receiveMessage(final Message message, final Acknowledgment acknowledgment, @Header("ApproximateReceiveCount") final int receiveCount) throws Exception {         final Reply reply = doStuff(message);          return reply;     } } 

This fails with a NonExistentQueue exception. But the queue exists, and the first two methods send messages to it just fine. What am I missing?! I have checked for typos a million times, I'm pretty sure that's not it :)

Just in case, this is my configuration:

@Bean public QueueMessagingTemplate queueMessagingTemplate(final AmazonSQSAsync amazonSqs, final ResourceIdResolver resourceIdResolver) {     final QueueMessagingTemplate queueMessagingTemplate = new QueueMessagingTemplate(amazonSqs, resourceIdResolver);     return queueMessagingTemplate; }  @Lazy @Bean(name = "amazonSQS", destroyMethod = "shutdown") public AmazonSQSAsync amazonSQSClient() {      final AmazonSQSAsync awsSQSAsyncClient;      awsSQSAsyncClient = AmazonSQSAsyncClientBuilder             .standard()             .withRegion(Regions.fromName(System.getProperty("cloud.aws.region.static")))             .withCredentials(new DefaultAWSCredentialsProviderChain())             .build();     return awsSQSAsyncClient; }  @Bean public QueueMessageHandler queueMessageHandler(final AmazonSQSAsync amazonSqs) {     final QueueMessageHandlerFactory queueMsgHandlerFactory = new QueueMessageHandlerFactory();     queueMsgHandlerFactory.setAmazonSqs(amazonSqs);      final QueueMessageHandler queueMessageHandler = queueMsgHandlerFactory.createQueueMessageHandler();      return queueMessageHandler; }  @Bean public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory(final AmazonSQSAsync amazonSqs) {     final SimpleMessageListenerContainerFactory msgListenerContainerFactory = new SimpleMessageListenerContainerFactory();     msgListenerContainerFactory.setAmazonSqs(amazonSqs);     msgListenerContainerFactory.setMaxNumberOfMessages(5);     msgListenerContainerFactory.setWaitTimeOut(20);      return msgListenerContainerFactory; }   @Bean public SimpleMessageListenerContainer simpleMessageListenerContainer(final QueueMessageHandler messageHandler, final SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory) {     final SimpleMessageListenerContainer msgListenerContainer = simpleMessageListenerContainerFactory.createSimpleMessageListenerContainer();     msgListenerContainer.setMessageHandler(messageHandler);      return msgListenerContainer; }  @Bean public DynamicQueueUrlDestinationResolver destinationResolver(final AmazonSQSAsync amazonSqs, final ResourceIdResolver resourceIdResolver) {     DynamicQueueUrlDestinationResolver destinationResolver = new DynamicQueueUrlDestinationResolver(amazonSqs, resourceIdResolver);     return destinationResolver; }  @Bean public QueueMessageHandlerFactory queueMessageHandlerFactory(final AmazonSQSAsync amazonSqs) {     QueueMessageHandlerFactory factory = new QueueMessageHandlerFactory();     factory.setAmazonSqs(amazonSqs);      return factory; } 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!