[Yandex Cloud documentation](../../../index.md) > [Yandex API Gateway](../../index.md) > [Concepts](../index.md) > [Trigger](index.md) > Trigger for Data Streams

# Trigger for Data Streams that sends messages to WebSocket connections

[A trigger](index.md) for Data Streams sends messages to [WebSocket connections](../extensions/websocket.md) when data is sent to a [stream](../../../data-streams/concepts/glossary.md#stream-concepts).

A trigger for Data Streams requires [service accounts](../../../iam/concepts/users/service-accounts.md) to manage the stream and send messages to WebSocket connections. You can use the same service account for both operations.

For more information about creating a trigger for Data Streams, see [Creating a trigger for Data Streams that sends messages to WebSocket connections](../../operations/trigger/data-streams-trigger-create.md).

## Message batching {#batching}

The batching settings allow sending several messages to WebSocket connections at a time. They set a top limit on a message batch size and its accumulation time. For example, if the message batch size is 3, WebSocket connections can receive batches containing from 1 to 3 messages.

## Roles required for the proper operation of a trigger for Data Streams {#roles}

* To create a trigger, you need a permission for the service account under which the trigger runs the operation. This permission comes with the [iam.serviceAccounts.user](../../../iam/concepts/access-control/roles.md#sa-user) and [editor](../../../iam/concepts/access-control/roles.md#editor) roles or higher.
* For the trigger to fire, service accounts need the following roles:
    * `api-gateway.websocketBroadcaster` for the folder containing the API gateway.
    * `yds.admin` for the stream that invokes the trigger when data is sent to it.

## Format of the message from the trigger for Data Streams {#format}

The trigger for Data Streams receives and sends messages in [JSON](https://enwikipedia.org/wiki/JSON) format only.

After the trigger fires, it will send a message with the `messages` array to WebSocket connections:

```json
{
   "messages":[
      {
         "key1":"value1"
      },
      {
         "key2":"value2"
      }
   ]
}
```

## Useful links {#see-also}

* [Trigger for Data Streams that runs a Serverless Containers container](../../../serverless-containers/concepts/trigger/data-streams-trigger.md)
* [Trigger for Data Streams that runs a Cloud Functions function](../../../functions/concepts/trigger/data-streams-trigger.md)