Receiving and deleting messages
Written by
Updated at October 4, 2024
Messages queued in Message Queue are received by consumers, i.e., components of distributed applications. After messages are received and processed, they should be deleted from the queue.
AWS CLI
-
Install and configure the AWS CLI.
-
Receive the message you sent earlier:
aws sqs receive-message \ --queue-url <queue_URL> \ --endpoint <endpoint>
Where:
--queue-url
: URL of the queue to receive the message from.--endpoint
: Endpoint set tohttps://message-queue.api.cloud.yandex.net/
.
Result:
{ "Messages": [ { "MessageId": "948de7-9ec8d787-c*******-*", "ReceiptHandle": "EAEggbj********", "MD5OfBody": "ed076287532e86365e841e92********", "Body": "Hello World", "Attributes": { "ApproximateFirstReceiveTimestamp": "15459********", "ApproximateReceiveCount": "1", "SentTimestamp": "15459********", "SenderId": "abcdefkbh72is78********" } } ] }
Save the
ReceiptHandle
value: you will need it later.Note
If there are no messages in the queue, the
aws sqs receive-message
command will end with no text output to the terminal. -
To delete a message from a queue, use the receipt ID: the
ReceiptHandle
parameter value received together with the message.Delete the received message from the queue:
aws sqs delete-message \ --queue-url <queue_URL> \ --endpoint <endpoint> \ --receipt-handle <receipt_ID>
Where:
--queue-url
: URL of the queue to delete the message from.--endpoint
: Endpoint set tohttps://message-queue.api.cloud.yandex.net/
.--receipt-handle
: Previously saved message receipt ID (ReceiptHandle
).
If the delete command is executed successfully, no text is output to the terminal. To check the deletion of the message:
Management console
- In the management console
, select the folder where you created the message queue. - In the list of services, select Message Queue.
- The current number of enqueued messages is specified in the Messages in queue field.