Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Message Queue
  • Getting started
    • Quick start
    • Supported tools
    • Code samples
      • Node.js
      • PHP
      • JMS
      • Laravel
      • Terraform
  • Step-by-step instructions
    • Overview
    • Creating a new message queue
    • Sending messages
    • Receiving and deleting messages
    • Deleting a message queue
    • Monitoring processes in queues
  • Concepts
    • Overview
    • Message queues
    • Messages
    • Deduplication
    • Visibility timeout
    • Long Polling
    • Dead Letter Queue
    • Delay queues
    • Quotas and limits
  • Practical guidelines
    • Converting a video to a GIF in Python
  • Access management
  • Pricing policy
  • Yandex Message Queue API
    • Overview
    • Queue
      • CreateQueue
      • DeleteQueue
      • GetQueueAttributes
      • GetQueueUrl
      • ListQueues
      • PurgeQueue
      • SetQueueAttributes
    • Message
      • ChangeMessageVisibility
      • ChangeMessageVisibilityBatch
      • DeleteMessage
      • DeleteMessageBatch
      • ReceiveMessage
      • SendMessage
      • SendMessageBatch
    • Data types
      • BatchResultErrorEntry
      • ChangeMessageVisibilityBatchRequestEntry
      • ChangeMessageVisibilityBatchResultEntry
      • DeleteMessageBatchRequestEntry
      • DeleteMessageBatchResultEntry
      • Message
      • MessageAttributeValue
      • SendMessageBatchRequestEntry
      • SendMessageBatchResultEntry
    • Common errors
  • Questions and answers
  1. Step-by-step instructions
  2. Creating a new message queue

Creating a new message queue

Written by
Yandex.Cloud

    To create a new message queue:

    Management console
    AWS CLI
    Terraform
    1. Open the Message Queue section.

    2. Click Create queue.

    3. Enter a name for the queue.

      The name may contain lowercase Latin letters, numbers, hyphens, and underscores. The name of a FIFO queue must end with the .fifo suffix. The name can't be longer than 80 characters.

    4. Select the queue type: Standard or FIFO.

    5. Specify the standard visibility timeout to be applied to enqueued messages after they are read by a consumer.

    6. Specify the message retention period.

    7. Specify the maximum message size.

    8. Specify the delivery delay: the amount of time during which a new message cannot be picked from a queue.

    9. Specify the message receipt timeout.

    10. Click Create queue.

    Run the following command in the terminal:

    $ aws sqs create-queue --queue-name sample-queue \
                --endpoint https://message-queue.api.cloud.yandex.net/
    {
        "QueueUrl": "https://message-queue.api.cloud.yandex.net/aoeaql9r10cd9cfue7v6/000000000000002n034r/sample-queue"
    }
    

    With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it by configuration files. They store the infrastructure description in HashiCorp Configuration Language (HCL). Terraform and its providers are distributed under the Mozilla Public License.

    For more information about the provider resources, see the documentation on the Terraform site or mirror site.

    If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.

    If you don't have Terraform yet, install it and configure the Yandex Cloud provider.

    To create a message queue:

    1. In the configuration file, describe the parameters of the queue to create:

      • name: Queue name.
      • visibility_timeout_seconds: Visibility timeout.
      • receive_wait_time_seconds: Waiting time for messages to enter the queue if Long Polling is used. Valid values: from 0 to 20 seconds. Default: 0 seconds.
      • message_retention_seconds: Length of time, in seconds, to retain a message in the queue.
      • redrive_policy: Message redrive policy in a Dead Letter Queue.
        • deadLetterTargetArn: ARN of the DLQ that messages are moved to.
        • maxReceiveCount: Number of attempts to read a message from the queue before redriving it to the DLQ.
      • fifo_queue: Indicates that a FIFO queue is created.
      • content_based_deduplication: Enables content-based deduplication in FIFO queues.
      • access_key: ID of the service account static access key for the queue. If it isn't specified in the queue configuration, the ID from the provider configuration is used.
      • secret_key: Secret part of the static access key. If no secret key is set in the queue configuration, the key from the provider configuration is used.

      Sample configuration file for a standard queue:

      provider "yandex" {
          token = "<OAuth or static key of service account>"
          folder_id = "<folder ID>"
          zone      = "ru-central1-a"
        }
      
      resource "yandex_message_queue" "example_queue" {
        name                        = "ymq-terraform-example"
        visibility_timeout_seconds  = 600
        receive_wait_time_seconds   = 20
        message_retention_seconds   = 1209600
        access_key                  = "<static access key ID>"
        secret_key                  = "<secret part of static access key>"
      }
      

      Sample configuration file for a FIFO queue:

      provider "yandex" {
          token = "<OAuth or static key of service account>"
          folder_id = "<folder ID>"
          zone      = "ru-central1-a"
        }
      
      resource "yandex_message_queue" "example-fifo-queue" {
        name                        = "ymq-terraform-example.fifo"
        visibility_timeout_seconds  = 600
        receive_wait_time_seconds   = 20
        message_retention_seconds   = 1209600
        fifo_queue                  = true
        access_key                  = "<static access key ID>"
        secret_key                  = "<secret part of static access key>"
      }
      

      Sample configuration file for a queue with a redrive policy for moving undelivered messages to a DLQ named ymq_terraform_deadletter_example:

      provider "yandex" {
          token = "<OAuth or static key of service account>"
          folder_id = "<folder ID>"
          zone      = "ru-central1-a"
        }
      
      resource "yandex_message_queue" "example_fifo_queue" {
        name                        = "ymq-terraform-example"
        visibility_timeout_seconds  = 600
        receive_wait_time_seconds   = 20
        message_retention_seconds   = 1209600
        redrive_policy              = jsonencode({
          deadLetterTargetArn = yandex_message_queue.example_deadletter_queue.arn
          maxReceiveCount     = 3
        })
        access_key                  = "<static access key ID>"
        secret_key                  = "<secret part of static access key>"
      }
      
      resource "yandex_message_queue" "example_deadletter_queue" {
        name                        = "ymq_terraform_deadletter_example"
        access_key                  = "<static access key ID>"
        secret_key                  = "<secret part of static access key>"
      }
      

      For more information about the resources you can create using Terraform, see the provider documentation.

    2. Make sure that the configuration files are correct.

      1. In the command line, go to the directory where you created the configuration file.

      2. Run the check using the command:

        $ terraform plan
        

      If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If there are errors in the configuration, Terraform points them out.

    3. Deploy the cloud resources.

      1. If the configuration doesn't contain any errors, run the command:

        $ terraform apply
        
      2. Confirm that you want to create the resources.

      Afterwards, all the necessary resources are created in the specified folder. You can check resource availability and their settings in the management console. To delete the created resources, run the terraform destroy command.

    Was the article helpful?

    Language / Region
    © 2022 Yandex.Cloud LLC