Trigger for Message Queue that passes messages to the Serverless Containers container
The trigger for Message Queue is used to process the message queue. It picks up messages from the queue and passes them to a Serverless Containers container for processing. Once successfully processed, a trigger deletes messages from the queue, and if an error occurs, it places messages back in the queue and sets a visibility timeout. If the queue does not have a Dead Letter Queue configured, a message will continue to be returned to a container until it is successfully processed or until its storage timeout expires.
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.
Triggers for Message Queue require service accounts to read messages from a message queue and invoke a container. You can use the same service account for both operations.
Roles required for the proper operation of a trigger for Message Queue
- To create a trigger, you need:
- The
viewer
role for the folder with the message queue that the trigger reads messages from. - The
viewer
role for the folder with the container that the trigger invokes. - Permission to the service account on whose behalf the trigger executes the operations. This permission is included in the iam.serviceAccounts.user and editor roles and higher.
- The
- To run a trigger, service accounts need the following roles:
editor
for the folder with the message queue that the trigger reads messages from.serverless.containers.invoker
for the folder with the container that invokes the trigger.
Read more about access management.
Trigger for Message Queue message format
After the trigger picks up a message from the queue, it passes it to the container in the following format:
{
"messages":[
{
"event_metadata":{
"event_id":"cce76685-5828-4304-a83d-95643c0507a0",
"event_type":"yandex.cloud.events.messagequeue.QueueMessage",
"created_at":"2019-09-24T00:54:28.980441Z"
},
"details":{
"queue_id": "yrn:yc:ymq:ru-central1:21i6v06sqmsaoeon7nus:event-queue",
"message":{
"message_id":"cce76685-5828-4304-a83d-95643c0507a0",
"md5_of_body":"d29343907090dff4cec4a9a0efb80d20",
"body":"message body",
"attributes":{
"SentTimestamp":"1569285804456"
},
"message_attributes":{
"messageAttributeKey":{
"dataType":"StringValue",
"stringValue":"value"
}
},
"md5_of_message_attributes":"83eb2d0afefb150c1ffe69f66c3de068"
}
}
},
{
"event_metadata":{
"event_id":"1f32fd25-11fc-4c08-88e7-d871d6ffb91d",
"event_type":"yandex.cloud.events.messagequeue.QueueMessage",
"created_at":"2019-09-24T00:54:28.980492Z"
},
"details":{
"queue_id": "yrn:yc:ymq:ru-central1:21i6v06sqmsaoeon7nus:event-queue",
"message":{
"message_id":"1f32fd25-11fc-4c08-88e7-d871d6ffb91d",
"md5_of_body":"d29343907090dff4cec4a9a0efb80d20",
"body":"message body",
"attributes":{
"SentTimestamp":"1569285806456"
},
"message_attributes":{
"messageAttributeKey":{
"dataType":"StringValue",
"stringValue":"value"
}
},
"md5_of_message_attributes":"83eb2d0afefb150c1ffe69f66c3de068"
}
}
}
]
}