Use the ably channels batch-publish command to publish a message to multiple Ably Pub/Sub channels at once.
Synopsis
ably channels batch-publish [message] [options]Arguments
message
The message to publish. This is optional when using the --spec option.
Options
--channels
A comma-separated list of channel names to publish to. This option is mutually exclusive with --channels-json and --spec.
--channels-json
A JSON array of channel names to publish to. This option is mutually exclusive with --channels and --spec.
--spec
A complete batch spec as a JSON string. This option is mutually exclusive with --channels and --channels-json.
--encoding | -e
The encoding of the message, such as json/utf-8.
--name | -n
The event name for the message.
--json
Output results as compact JSON. Mutually exclusive with --pretty-json.
--pretty-json
Output results in formatted JSON. Mutually exclusive with --json.
--verbose | -v
Enable verbose logging. Can be combined with --json or --pretty-json.
Examples
Publish to multiple channels:
ably channels batch-publish "Hello, everyone!" --channels "channel-1,channel-2,channel-3"Publish using a JSON array of channels:
ably channels batch-publish "Hello!" --channels-json '["channel-1", "channel-2"]'Publish using a complete batch spec:
ably channels batch-publish --spec '{"channels": ["channel-1", "channel-2"], "messages": [{"data": "Hello!"}]}'Batch publish with an event name:
ably channels batch-publish --channels channel1,channel2 --name event '{"text":"Hello World"}'Batch publish using an array of batch specs for different channels:
ably channels batch-publish --spec '[{"channels": "channel1", "messages": {"data": "First spec"}}, {"channels": "channel2", "messages": {"data": "Second spec"}}]'Batch publish and output the result in JSON format:
ably channels batch-publish --channels channel1,channel2 '{"data":"Message"}' --jsonBatch publish and output the result in formatted JSON:
ably channels batch-publish --channels channel1,channel2 '{"data":"Message"}' --pretty-jsonSee also
- Channels — Explore all
ably channelscommands. - CLI reference — Full list of available commands.