Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Blog
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
Yandex Serverless Containers
  • Comparison with other Yandex Cloud services
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Getting an IAM token for a service account using a container
    • Getting information about a container
    • Managing rights to access a container
    • Creating a container
    • Invoking a container
    • Managing a container
    • Getting information about a trigger
    • Creating a trigger
      • Create a timer
      • Creating a trigger for Message Queue
      • Creating a trigger for Object Storage
      • Creating a trigger for Container Registry
      • Creating a trigger for Cloud Logging
      • Creating a trigger for Yandex IoT Core
      • Creating a trigger for budgets
      • Creating a trigger for Data Streams
      • Creating an email trigger
    • Managing triggers
  • Concepts
  • Practical guidelines
  • Access management
  • Pricing policy
  • Containers API reference
  • API Triggers reference
  • Questions and answers
  1. Step-by-step instructions
  2. Creating a trigger
  3. Creating a trigger for Message Queue

Creating a trigger for Message Queue that sends messages to a Serverless Containers container

Written by
Yandex Cloud
  • Before you begin
  • Creating a trigger
  • Checking the result
  • See also

Create a trigger for a Message Queue message queue and process the messages using the Serverless Containers container.

Warning

  • You can only create a trigger for a standard message queue.
  • The trigger must be in the same cloud as the queue that messages are read from.
  • Only one trigger can be created for each message queue.

Before you begin

To create a trigger, you need:

  • A container that the trigger will invoke. If you don't have a container:

    • Create a container.
    • Create a container revision.
  • Service accounts with rights:

    • To invoke a container.
    • To read from the queue the trigger receives messages from.
    • (optional) To write to the Dead Letter Queue.

    You can use the same service account or different ones. If you don't have a service account, create one.

  • A message queue that the trigger receives messages from. If you don't have a queue, create one.

Creating a trigger

Note

The trigger is initiated within 5 minutes of being created.

Management console
CLI
API
  1. In the management console, select the folder where you wish to create your trigger.

  2. Open Serverless Containers.

  3. On the left-hand panel, select Triggers.

  4. Click Create trigger.

  5. Under Basic parameters:

    • Enter a name and description for the trigger.
    • In the Type field, select Message Queue.
    • In the Launched resource field, select Container.
  6. Under Message Queue settings, select a message queue and a service account with rights to read messages from this message queue.

  7. (optional) Under Batch message settings, specify:

    • Batch size. Values can be from 1 to 10. The default is 1.
    • Maximum wait time. Values can be from 0 to 20 seconds. The default is 10 seconds.

    The trigger groups messages for a period of time not exceeding the specified timeout and sends them to a container. However, the number of messages does not exceed the specified group size.

  8. Under Container settings, select a container and specify:

    • A container revision.
    • A service account to be used to invoke the container.
  9. Click Create trigger.

If you don't have the Yandex Cloud command line interface yet, install and initialize it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

To create a trigger that invokes a container, run the command:

yc serverless trigger create message-queue \
  --name <trigger_name> \
  --queue <queue_ID> \
  --queue-service-account-id <service_account_ID> \
  --invoke-container-id <container_ID> \
  --invoke-container-service-account-id <service_account_ID> \
  --batch-size 1 \
  --batch-cutoff 10s

Where:

  • --name: Trigger name.

  • --queue: Queue ID.

    To find out the queue ID:

    1. In the management console, select the folder containing the queue.
    2. Select Message Queue.
    3. Select the desired queue.
    4. You can see the queue ID under General information in the ARN field.
  • --invoke-container-id: Container ID.

  • --queue-service-account-name: Service account with rights to read messages from the queue.

  • --invoke-container-service-account-id: Service account with rights to invoke the container.

  • --batch-size: Message batch size. This is an optional parameter. Values can be from 1 to 10. The default is 1.

  • --batch-cutoff: Maximum waiting time. This is an optional parameter. Values can be from 0 to 20 seconds. The default is 10 seconds. The trigger groups messages for a period not exceeding batch-cutoff and sends them to a container. At the same time, the number of messages does not exceed batch-size.

Result:

id: a1s5msktij**********
folder_id: b1gmit33hg**********
created_at: "2022-10-24T15:19:15.353909857Z"
name: ymq-trigger
rule:
  message_queue:
    queue_id: yrn:yc:ymq:ru-central1:b1gmit33ng**********:my-mq
    service_account_id: bfbqqeo6jk**********
    batch_settings:
      size: "1"
      cutoff: 10s
    invoke_container:
      container_id: bba5jb38o8**********
      service_account_id: bfbqqeo6jk**********
status: ACTIVE

You can create a trigger for Message Queue using the create.

Checking the result

Serverless Containers
Message Queue

Make sure the trigger is working properly. To do this, view container logs that show information about invocations.

Check that the number of enqueued messages is decreasing. To do this, view the queue statistics:

  1. In the management console, open Message Queue.
  2. Select the queue that you created the trigger for.
  3. Go to Monitoring. View the Messages in queue chart.

See also

  • Trigger for Message Queue that sends messages to the Cloud Functions function.

Was the article helpful?

Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
In this article:
  • Before you begin
  • Creating a trigger
  • Checking the result
  • See also