DEV Community

OdunayoO
OdunayoO

Posted on

What is AWS SQS (Simple Queue Service)?

AWS SQS is a messaging queue service provided by AWS. Sometimes you can have many applications deployed on AWS, and with SQS you can easily communicate with your services.

These communications may be synchronous(where your applications directly communicate with each other) or asynchronous(where you can have a middleware that connects these applications)

Before we dive into the features of SQS, we need to understand some concepts.

  • Message: It is a blob that can contain any data
  • Queue: You can imagine a queue as a temporary house that allows you to store messages till the messages are processed and deleted.
  • Polling: This is a mechanism that can be used to receive messages from queues.
  • Producer: A producer sends messages to the queue. You can have one or more producers sending messages to the queue
  • Consumer: A consumer receives(polls) messages from the queue. You can have multiple consumers.

Features of AWS SQS

  • Visibility Timeout
    When a message is polled and processed by the consumer, it remains in the queue and does not get deleted automatically. While the message is being processed, SQS will set a time during which the message because invisible to other consumers, to prevent them from receiving and processing the message. By default, the visibility timeout is 30 seconds, with a minimum time of 0 seconds and a maximum time of 12 hours.

  • Dead-Letter Queues
    So what if a message is not processed within the visibility timeout? The message goes back into the message queue and is then retried to be processed until a maximum number is reached before it is then sent to the dead-letter queue. One useful thing about DLQs is that it allows you to debug your applications easily by isolating the messages that fail to be processed.

  • FIFO Queues
    FIFO means First In First Out which is the order in which messages are being sent and received by the consumer. The FIFO queue supports up to 300 messages per second. If you're using FIFO queues, dead-letter queues can break the order.

  • Delay Queues
    With delay queues, messages can be delayed before they are delivered. Any message sent to this queue would be invisible to the consumers for the duration of the delay period. By default, the minimum delay period is 0 seconds and maximum time of 15 minutes. Unlike the visibility timeout where messages are hidden until they are consumed, with delay queues the messages are hidden as soon as it is added to the queue.

SQS Hands-On

How to create an Amazon SQS queue from AWS console

  • on the console search for SQS
  • click on create queue
  • for the type you can choose the standard or FIFO queue, by default the queue is set to standard standard or FIFO queue
  • enter a name for your queue
  • under Configuration, you can leave it as the default or set new values set Configuration
  • by default AWS SQS manages server-side encryption. You can disable it or choose an encryption key
  • you can also choose who can access your queue. For the basic option, define who can send messages to the queue and who can receive messages from the queue. For the advanced option, the JSON object can be modified directly and custom actions can be set.
  • you can modify the redrive allow policy (optional)
  • you can also enable dead-letter-queue (optional) and lastly add tags(optional)
  • Finally, your queue has been created!!!

queue created
You can:

  • edit: modify queue
  • delete the queue
  • purge: delete all the messages created
  • send and receive message

How to send and receive messages

  • click on the send and receive message
  • enter your message in the message body

enter your message

  • click on send message

send the message

  • scroll down to receive message
  • click on poll for messages

poll for messages

  • your created message should appear

your created message should appear

  • click on the id to see more details about the message

click on id

  • after processing and receiving the message, you can delete it manually

delete messages manually

Conclusion: When can you use SQS?

  • It can be used to decouple and scale services
  • Multiple SQS queues can be used to process messages in parallel
  • Together with AWS SNS(Simple Notification Service), SQS can be used for monitoring and creating alerts in your application

Top comments (0)