Amazon Simple Queue Service

Transcription

Amazon Simple Queue ServiceDeveloper Guide

Amazon Simple Queue Service Developer GuideAmazon Simple Queue Service: Developer GuideCopyright Amazon Web Services, Inc. and/or its affiliates. All rights reserved.Amazon's trademarks and trade dress may not be used in connection with any product or service that is notAmazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages ordiscredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who mayor may not be affiliated with, connected to, or sponsored by Amazon.

Amazon Simple Queue Service Developer GuideTable of ContentsWhat is Amazon SQS? . 1Benefits of using Amazon SQS . 1Differences between Amazon SQS, Amazon MQ, and Amazon SNS . 1Queue types . 2Common tasks for getting started with Amazon SQS . 3Pricing for Amazon SQS . 3Setting up . 4Step 1: Create an AWS account . 4Step 2: Create an IAM user . 4Step 3: Get your access key ID and secret access key . 5Step 4: Get ready to use the example code . 6Next steps . 6Getting started . 7Prerequisites . 7Step 1: Create a queue . 7Step 2: Send a message . 7Step 3: Receive and delete your message . 8Step 4: Delete your queue . 9Next steps . 9Configuring Amazon SQS . 10Understanding the Amazon SQS console . 10Creating a queue . 11Editing a queue . 12Configuring queue parameters . 12Configuring access policy . 14Configuring SSE for a queue . 14Configuring a dead-letter queue . 15Configuring tags for a queue . 15Subscribing a queue to a topic . 16Configuring a Lambda trigger . 16Prerequisites . 17Managing queues . 18Sending messages . 18Message attributes . 19Receiving and deleting a message . 20Purging a queue . 20Deleting a queue . 21Confirming that a queue is empty . 21How Amazon SQS works . 23Basic architecture . 23Distributed queues . 23Message lifecycle . 24Standard queues . 25Message ordering . 26At-least-once delivery . 26FIFO queues . 26Message ordering . 27Key terms . 27FIFO delivery logic . 28Exactly-once processing . 29Moving from a standard queue to a FIFO queue . 29High throughput for FIFO queues . 30Compatibility . 35Queue and message identifiers . 35iii

Amazon Simple Queue Service Developer GuideIdentifiers for Standard and FIFO queues .Additional identifiers for FIFO queues .Message metadata .Message attributes .Message system attributes .Resources required to process messages .List queue pagination .Cost allocation tags .Short and long polling .Consuming messages using short polling .Consuming messages using long polling .Differences between long and short polling .Dead-letter queues .How do dead-letter queues work? .What are the benefits of dead-letter queues? .How do different queue types handle message failure? .When should I use a dead-letter queue? .Troubleshooting dead-letter queues .Visibility timeout .Inflight messages .Setting the visibility timeout .Changing the visibility timeout for a message .Terminating the visibility timeout for a message .Delay queues .Temporary queues .Virtual queues .Request-response messaging pattern (virtual queues) .Example scenario: Processing a login request .Cleaning up queues .Message timers .Best practices .Recommendations for standard and FIFO queues .Working with messages .Reducing costs .Moving from a Standard queue to a FIFO queue .Additional recommendations for FIFO queues .Using the message deduplication ID .Using the message group ID .Using the receive request attempt ID .Java SDK examples .Using server-side encryption .Adding SSE to an existing queue .Disabling SSE for a queue .Creating a queue with SSE .Retrieving SSE attributes .Configuring tags .Listing tags .Adding or updating tags .Removing tags .Sending message attributes .Defining attributes .Sending a message with attributes .Managing large messages .Prerequisites .Example: Using Amazon S3 to manage large Amazon SQS messages .Working with JMS .Prerequisites 46464656666667070

Amazon Simple Queue Service Developer GuideGetting started with the Java Messaging Library . 71Creating a JMS connection . 71Creating an Amazon SQS queue . 72Sending messages synchronously . 72Receiving messages synchronously . 73Receiving messages asynchronously . 74Using client acknowledge mode . 75Using unordered acknowledge mode . 76Using the JMS Client with other Amazon SQS clients . 76Working Java example for using JMS with Amazon SQS Standard queues . 77ExampleConfiguration.java . 77TextMessageSender.java . 79SyncMessageReceiver.java . 80AsyncMessageReceiver.java . 82SyncMessageReceiverClientAcknowledge.java . 83SyncMessageReceiverUnorderedAcknowledge.java . 85SpringExampleConfiguration.xml . 88SpringExample.java . 89ExampleCommon.java . 90Supported JMS 1.1 implementations . 91Supported common interfaces . 91Supported message types . 92Supported message acknowledgment modes . 92JMS-defined headers and reserved properties . 92Tutorials . 93Creating an Amazon SQS queue (AWS CloudFormation) . 93Sending a message from a VPC . 94Step 1: Create an Amazon EC2 key pair . 95Step 2: Create AWS resources . 95Step 3: Confirm that your EC2 instance isn't publicly accessible . 96Step 4: Create an Amazon VPC endpoint for Amazon SQS . 96Step 5: Send a message to your Amazon SQS queue . 97Quotas . 99Quotas related to queues . 99Quotas related to messages . 100Quotas related to policies . 103Automating and troubleshooting . 104Automating notifications using EventBridge . 104Troubleshooting queues using X-Ray .

delivered in an order different from which they were sent. High Throughput – If you use batching (p. 160), FIFO queues support up to 3,000 transactions per second, per API method (SendMessageBatch, ReceiveMessage, or DeleteMessageBatch). The 3000 transactions represent 300 API calls, each with a batch of 10 messages. To request a