AWS Simple Queue Service (Amazon SQS)學習筆記

Amazon SQS is a fast, reliable, scalable, and fully managed message queuing service. Amazon SQS makes it simple and cost effective to decouple the components of a cloud application.
You can use Amazon SQS to transmit any volume of data, at any level of throughput, without losing messages or requiring other services to be continuously available.

Amazon SQS ensures delivery of each message at least once and supports multiple readers and writers interacting with the same queue.

Message Lifecycle

在這裏插入圖片描述
Message lifecycle

  1. Component 1 sends Message A to a queue, and the message is redundantly distributed across the Amazon SQS servers.
  2. When Component 2 is ready to process a message, it retrieves messages from the queue,and Message A is returned. While Message A is being processed, it remains in the queue and is not returned to subsequently receive requests for the duration of the visibility timeout.
  3. Component 2 deletes Message A from the queue to prevent the message from being
    received and processed again after the visibility timeout expires.

Delay Queues and Visibility Timeouts

Delay queues allow you to postpone the delivery of new messages in a queue for a specific number of seconds.
Delay queues are similar to visibility timeouts in that both features make messages.
unavailable to consumers for a specific period of time. The difference is that a delay queue hides a message when it is first added to the queue, whereas a visibility timeout hides a message only after that message is retrieved from the queue.

Diagram of visibility timeout
在這裏插入圖片描述
You can have up to 120,000 messages in flight at any given time.
Amazon SQS supports up to 12 hours’ maximum visibility timeout.

Queue Operations, Unique IDs, and Metadata

Your messages are identified via a globally unique ID that Amazon SQS returns when the message is delivered to the queue.
When you receive a message from the queue, the response includes a receipt handle, which you must provide when deleting the message.

Queue and Message Identifiers

Amazon SQS uses three identifiers that you need to be familiar with: queue URLs, message IDs, and receipt handles.
Amazon SQS assigns each queue an identifier called a queue URL.

Each time you receive a message from a queue, you receive a receipt handle for that message.
The handle is associated with the act of receiving the message, not with the message itself. As stated previously, to delete the message or to change the message visibility, you must provide the receipt handle and not the message ID.

Message Attributes

Message attributes allow you to provide structured metadata items (such as timestamps, geospatial data, signatures, and identifiers) about the message.
Message attributes are optional and separate from, but sent along with, the message body.
Each message can have up to 10 attributes.

Long Polling

the constant calls to ReceiveMessage burn CPU cycles and tie up a thread.
In this situation, you will want to use long polling. With long polling, you send a WaitTimeSeconds argument to ReceiveMessage of up to 20 seconds.

Dead Letter Queues

Amazon SQS provides support for dead letter queues. A dead letter queue is a queue that other (source) queues can target to send messages that for some reason could not be successfully processed. A primary benefit of using a dead letter queue is the ability to sideline and isolate the unsuccessfully processed messages.

Access Control

Amazon SQS Access Control allows you to assign policies to queues that grant specific
interactions to other accounts without that account having to assume IAM roles from your account. These policies are written in the same JSON language as IAM.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章