简体   繁体   中英

Use SQS queueName instead of URL in case of AmazonSQS

I have the following code to receive messages from 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?

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. 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.)

Presumably for this reason, the SQS Query API (the web service used by the SDKs) requires the Queue URL be included in the request. 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. 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. The active tab at the top of the screen is hard to read but it appears to say "Make Money."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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