Sending events directly to a bus
Note
You can send events to a bus directly only if there is at least one rule attached to it.
To send events directly to a bus:
- In the management console
, navigate to the folder with the bus you need. - In the list of services, select Serverless Integrations.
- In the left-hand panel, select
EventRouter. - Select the bus you need.
- In the top panel, click
Send event. - In the window that opens, enter the event you need to send to the bus in JSON
format, e.g.,{"name": "value"}. - Click Send.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
-
View the description of the CLI command to send events directly to a bus:
yc serverless eventrouter put-event --help -
Get a list of buses:
yc serverless eventrouter bus listResult:
+----------------------+------------------+----------------------+--------+---------------------+ | ID | NAME | FOLDER ID | STATUS | DELETION PROTECTION | +----------------------+------------------+----------------------+--------+---------------------+ | f6676a9ti657******** | my-new-bus-17 | b1g681qpemb4******** | ACTIVE | false | | f66aevm4ithv******** | my-favourite-bus | b1g681qpemb4******** | ACTIVE | true | | f66m2q222n92******** | my-bus-42 | b1g681qpemb4******** | ACTIVE | false | +----------------------+------------------+----------------------+--------+---------------------+ -
Send the event to the bus you selected:
yc serverless eventrouter put-event \ --name <bus_name> \ --event '<event>' \ --file <file_path>Where:
-
--name: Name of the bus you are sending the event to.Instead of the bus name, you can provide its ID in the
--idparameter. -
--event: Event in JSON format, e.g.,{"name": "value"}. -
--file: Path to the file containing the event you are sending to the bus in JSON format.
The
--eventand--fileparameters are mutually exclusive: you can use only one of them. -
Use the EventService/Put gRPC API call to send the event directly to a bus:
-
If you do not have the gRPCurl utility installed, install
it. -
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
-
Get an IAM token used for authentication in the API.
IAM_TOKEN=$(yc iam create-token)The command will save the IAM token to the
IAM_TOKENvariable. -
Get a list of buses:
yc serverless eventrouter bus listResult:
+----------------------+------------------+----------------------+--------+---------------------+ | ID | NAME | FOLDER ID | STATUS | DELETION PROTECTION | +----------------------+------------------+----------------------+--------+---------------------+ | f6676a9ti657******** | my-new-bus-17 | b1g681qpemb4******** | ACTIVE | false | | f66aevm4ithv******** | my-favourite-bus | b1g681qpemb4******** | ACTIVE | true | | f66m2q222n92******** | my-bus-42 | b1g681qpemb4******** | ACTIVE | false | +----------------------+------------------+----------------------+--------+---------------------+ -
Create a file with the request body, e.g.,
body.json:{ "bus_id": "<bus_ID>", "body": "<event>" }Where:
bus_id: ID of the bus you are sending the event to.body: Event in JSON format, e.g.,{'name': 'value'}.
-
Run a gRPC call by specifying the path to the
body.jsonfile you created earlier:grpcurl \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d @ < body.json \ events.eventrouter.serverless.yandexcloud.net:443 yandex.cloud.serverless.eventrouter.v1.EventService/Put