Getting started with Message Queue
Let's perform the basic actions using the AWS CLI
-
Install
the AWS CLI, a command line utility for working with Message Queue. -
Create a service account with the
editor
role. -
Create static access keys. Save the ID and secret key to a secure location. You will not be able to view the secret key parameters again after you close the window.
-
Set up the AWS CLI:
-
Launch the interactive profile setup:
aws configure
-
Specify the service account key ID you obtained earlier:
AWS Access Key ID [****************ver_]: <service_account_key_ID>
-
Specify the service account secret key you obtained earlier:
AWS Secret Access Key [****************w5lb]: <service_account_secret_key>
-
Specify the
ru-central1
default region name:Default region name [ru-central1]: ru-central1
-
Specify
json
as the default format for output data:Default output format [None]: json
-
To view the current profile settings, run this command:
aws configure list
Result:
Name Value Type Location ---- ----- ---- -------- profile <not set> None None access_key ****************aBc1 shared-credentials-file secret_key ****************DeF2 shared-credentials-file region ru-central1 config-file ~/.aws/config
-
-
Create a queue named
sample-queue
:AWS CLIManagement consoleaws sqs create-queue \ --queue-name <queue_name> \ --endpoint <endpoint>
Where:
--queue-name
: Name of the new queue, e.g.,sample-queue
.--endpoint
: Endpoint in thehttps://message-queue.api.cloud.yandex.net/
value.
Result:
{ "QueueUrl": "https://message-queue.api.cloud.yandex.net/aoeaql9r10cd********/000000000000********/sample-queue" }
Save the obtained queue URL. You will need it at the next steps.
-
In the management console
, select the folder to create the queue in. -
Select Message Queue.
-
Click Create queue.
-
Enter a name for the queue:
sample-queue
.The name may contain lowercase Latin letters, numbers, hyphens, and underscores. The FIFO queue name must end with the
.fifo
suffix. The name may not be longer than 80 characters. -
Select the
Standard
type. Do not change other settings. -
Click Create.
-
Open the queue you created.
-
In the Overview tab, under General information, copy the queue URL as you will need it later.
-
Send a message to the created queue using the saved queue URL:
AWS CLIaws sqs send-message \ --message-body "<message_text>" \ --endpoint <endpoint> \ --queue-url <queue_URL>
Where:
--message-body
: Text of the message you want to send to the queue, e.g.,Hello World
.--endpoint
: Endpoint in thehttps://message-queue.api.cloud.yandex.net/
value.--queue-url
: URL of the queue the message will be sent to.
Result:
{ "MD5OfMessageBody": "67e63db14341b5a696596634********", "MessageId": "765ff4d2-fa4bc83-6cfcc***-*****" }
-
Accept the message from the queue:
AWS CLIaws sqs receive-message \ --endpoint <endpoint> \ --queue-url <queue_URL>
Where:
--endpoint
: Endpoint in thehttps://message-queue.api.cloud.yandex.net/
value.--queue-url
: URL of the queue to receive the message from.
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
parameter value. You will need it at the next steps. -
Delete the message from the queue.
After messages are processed, they should be deleted from the queue for applications not to process them again.
To delete a message received from the queue, use the
ReceiptHandle
parameter value you saved earlier:AWS CLIaws sqs delete-message \ --endpoint <endpoint> \ --queue-url <queue_URL> --receipt-handle <receipt_ID>
Where:
--endpoint
: Endpoint in thehttps://message-queue.api.cloud.yandex.net/
value.--queue-url
: URL of the queue to delete the message from.--receipt-handle
: Previously saved message receipt ID (ReceiptHandle
).
-
Delete the queue:
AWS CLIManagement consoleaws sqs delete-queue \ --endpoint <endpoint> \ --queue-url <queue_URL>
Where:
--endpoint
: Endpoint in thehttps://message-queue.api.cloud.yandex.net/
value.--queue-url
: URL of the queue you need to delete.
- In the management console
, select the folder the queue belongs to. - Select Message Queue.
- Click
next to the appropriate queue and select Delete. - In the window that opens, click Delete.