【问题标题】:The specified queue does not exist - AWS.SimpleQueueService.NonExistentQueue with Spring-Boot指定的队列不存在 - AWS.SimpleQueueService.NonExistentQueue with Spring-Boot
【发布时间】:2020-02-08 22:38:08
【问题描述】:

我无法在 Spring Boot 应用程序中附加 @SqsListener。它抛出 AWS.SimpleQueueService.NonExistentQueue 异常。

我已经解决了这个问题:Specified queue does not exist 据我所知,所有配置都是正确的。

@Component
public class SQSListenerImpl{
    @SqsListener(value = Constants.SQS_REQUEST_QUEUE, deletionPolicy = SqsMessageDeletionPolicy.NEVER)
    public void listen(String taskJson, Acknowledgment acknowledgment, @Headers Map<String, String> headers) throws ExecutionException, InterruptedException {
        //stuff
    }

    @PostConstruct
    private void init(){
        final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
        LOGGER.info("Listing all queues in your account.\n");
        for (final String queueUrl : sqs.listQueues().getQueueUrls()) {
            LOGGER.info("  QueueUrl: " + queueUrl);
        }
    }
}

application.properties

cloud.aws.stack.auto=false
cloud.aws.region.static=ap-southeast-1
logging.level.root=INFO

以上代码的日志:

[requestId: MainThread] [INFO] [SQSListenerImpl] [main]   QueueUrl: https://sqs.ap-southeast-1.amazonaws.com/xxxxx/hello-world
[requestId: MainThread] [INFO] [SQSListenerImpl] [main]   QueueUrl: https://sqs.ap-southeast-1.amazonaws.com/xxxxx/some-name2
[requestId: MainThread] [INFO] [SQSListenerImpl] [main]   QueueUrl: https://sqs.ap-southeast-1.amazonaws.com/xxxxx/some-name3
[requestId: MainThread] [WARN] [SimpleMessageListenerContainer] [main] Ignoring queue with name 'hello-world': The queue does not exist.; nested exception is com.amazonaws.services.sqs.model.QueueDoesNotExistException: The specified queue does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: 3c0108aa-7611-528f-ac69-5eb01fasb9f3)
[requestId: MainThread] [INFO] [Http11NioProtocol] [main] Starting ProtocolHandler ["http-nio-8080"]
[requestId: MainThread] [INFO] [TomcatWebServer] [main] Tomcat started on port(s): 8080 (http) with context path ''
[requestId: MainThread] [INFO] [Startup] [main] Started Startup in 11.391 seconds (JVM running for 12.426)

使用的 Aws 凭据位于 ~/.aws/ 目录下。

现在我的问题是,如果sqs.listQueues() 可以看到队列,那么为什么@SqsListener 不能?我错过了什么或做错了什么?

【问题讨论】:

    标签: java amazon-web-services spring-boot aws-sdk amazon-sqs


    【解决方案1】:

    我尝试像您一样使用 SpringBoot Aws clound 并得到同样的错误。 然后我使用完整的 http url 作为队列名称并得到拒绝访问错误

    @SqsListener(value = "https://sqs.ap-southeast-1.amazonaws.com/xxxxx/hello-world")
    

    所以最后,我最终直接使用 AWS SDK 从 SQS 获取消息

    【讨论】:

      【解决方案2】:

      这就是我对 Spring Cloud 所做的事情。

      使用 SPEL,我将 application.properties 中的一个值附加到注释 @SqsListener,如下所示

      @SqsListener(value = "#{queueConfiguration.getQueue()}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
      

      有一点需要注意,确保您使用队列的完整 HTTPS 路径。

      对于所有本地开发,我使用“localstack”并使用 SQS 的本地实现,但在 ECS 中部署时应用相同的代码。需要注意的另一点是角色或实例需要能够通过 IAM 接收消息才能实现这一点。

      【讨论】:

        猜你喜欢
        • 2015-03-20
        • 1970-01-01
        • 2015-11-30
        • 2017-12-11
        • 1970-01-01
        • 1970-01-01
        • 2021-10-15
        • 2021-09-03
        相关资源
        最近更新 更多