Receiving and deleting a message

To receive a message, we will use the command line with the aws sqs receive-message command; we will need to specify the --queue-url attribute to point our command at the queue.

In our example, the command to run would be this:

aws sqs receive-message 
--queue-url "https://us-east-2.queue.amazonaws.com/866117724370/markocloud"

And the response would be as follows:

{
"Messages": [
{
"Body": "This is a test message ", "ReceiptHandle": "AQEBE9Pi+P5RP9FoZxgQ8xtDVT4qetd060GmD6LVr3s3iltZpAixsujI/2xEE4FqD/Mrxa4H98hSxT6Gcn2l5L0jtJRlrtVK9kl/xpjwjQqoTsEh5i9B9WWDly/QQPj6RpeL7BvfytoQ7I25DqlTHwZQMEhGgD29vJ5FzYFi8WSc7+mVozTwSOsqXM0PeoCOMnlP8UaBFniRCIVvk9HbNFE198zC+F1bDL682NfRJA7SBgRMyjaVxSauQ9hkh/5UZJElSHiYaJtEKKbYXzfosaAeHq3BNEZGQk2KV33IAnJJx1H2w7g6tODAeRF7yhVOuWAsVXfm1eSFQ46DCH9o7kAAsxEYXYO19o0uNyjMwadHA0U0CD/4inoehQAtugF2AlNEzoyTaYVLCz+ZKRVbe9wSMw==",
"MD5OfBody": "2309502dc5493f110869b570d9028942",
"MessageId": "2e50bc36-90d6-4ef9-82d2-5769462394f0"
}
]
}

The structure of the response is as follows:

  • "Body": Represents the message content
  • "ReceiptHandle": Is the unique identifier for the message that was received
  • "MD5OfBody": The MD5 sum of the body of the message, used for delivery consistency
  • "MessageId": The identifier of the message in the queue

After we have finished processing the message, we can delete the message by specifying the aws sqs delete-message command with the --queue-url and --receipt-handle options, which are required to identify the message queue and message we are deleting. In our example, this command would look like this:

aws sqs delete-message 
--queue-url "https://us-east-2.queue.amazonaws.com/866117724370/markocloud"
--receipt-handle "AQEBE9Pi+P5RP9FoZxgQ8xtDVT4qetd060GmD6LVr3s3iltZpAixsujI/2xEE4FqD/Mrxa4H98hSxT6Gcn2l5L0jtJRlrtVK9kl/xpjwjQqoTsEh5i9B9WWDly/QQPj6RpeL7BvfytoQ7I25DqlTHwZQMEhGgD29vJ5FzYFi8WSc7+mVozTwSOsqXM0PeoCOMnlP8UaBFniRCIVvk9HbNFE198zC+F1bDL682NfRJA7SBgRMyjaVxSauQ9hkh/5UZJElSHiYaJtEKKbYXzfosaAeHq3BNEZGQk2KV33IAnJJx1H2w7g6tODAeRF7yhVOuWAsVXfm1eSFQ46DCH9o7kAAsxEYXYO19o0uNyjMwadHA0U0CD/4inoehQAtugF2AlNEzoyTaYVLCz+ZKRVbe9wSMw=="

The CLI command would now remove the message from the queue, and there are now no messages in the message queue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.179.100