简体   繁体   English

如果是AmazonSQS,请使用SQS queueName而不是URL

[英]Use SQS queueName instead of URL in case of AmazonSQS

I have the following code to receive messages from SQS: 我有以下代码来接收来自SQS的消息:

        ReceiveMessageRequest receiveMessageRequest = new
                ReceiveMessageRequest();
        receiveMessageRequest.setQueueUrl(queueUrl);
        receiveMessageRequest.setMaxNumberOfMessages(sqsBatchSize);

            ReceiveMessageResult messageResult = sqsClient.receiveMessage(receiveMessageRequest);

Is there any way I can pass the queueName instead of passing the queueURL in the ReceiveMessageRequest object? 有什么方法可以传递queueName而不是在ReceiveMessageRequest对象中传递queueURL吗?

Oddly, there isn't. 奇怪的是,没有。

Well, it's not actually that odd. 好吧,这实际上并不奇怪。 Queue names are only unique at the region level within each AWS account (not globally unique in one account or across multiple accounts) and it's possible for another account to grant you permission to access their queue, so the queue name by itself is not enough information to identify which queue you intend to access. 队列名称仅在每个AWS账户内的区域级别是唯一的(在一个账户或多个账户中不是全局唯一的),并且另一个账户可能会授予您访问其队列的权限,因此队列名称本身不足以提供信息以确定要访问的队列。 The account number and region are also needed. 还需要帐号和地区。 (The region wasn't originally a consideration, in the early days of SQS, since there was only one region.) (在SQS成立之初,该区域最初不是考虑因素,因为只有一个区域。)

Presumably for this reason, the SQS Query API (the web service used by the SDKs) requires the Queue URL be included in the request. 大概是由于这个原因,SQS查询API(SDK使用的Web服务) 要求在请求中包含队列URL It's a value that uniquely identifies a queue, because the account, region, and queue name are all embedded in it. 这是一个唯一标识队列的值,因为帐户,区域和队列名称都嵌入其中。

The queue could alternately have been identified by ARN, and this would make sense too, but it's possible that ARNs hadn't even been invented yet back when SQS was first launched over a decade ago. ARN可能已经识别出队列,这也很有意义,但是有可能早在十年前SQS首次发布时就尚未发明ARN。 SQS was the first-ever AWS service, and this blog post about it, from 2006 contains a screen shot that's priceless classic old school Amazon. SQS是有史以来的第一个AWS服务, 有关此内容的此博客文章始于2006年,其中包含一个屏幕快照,该屏幕快照是无价的经典老式Amazon。 The active tab at the top of the screen is hard to read but it appears to say "Make Money." 屏幕顶部的活动标签很难阅读,但似乎显示“赚钱”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM