Use the ably channels publish command to publish a message to an Ably Pub/Sub channel.
Synopsis
ably channels publish <channel-name> <message> [options]Arguments
channel-name Required
The name of the channel to publish to.
message Required
The message to publish. This can be plain text or JSON. Supports {{.Count}} and {{.Timestamp}} interpolation when publishing multiple messages.
Options
--count | -c
The number of messages to publish. Defaults to 1.
--delay | -d
The delay between messages in milliseconds when publishing multiple messages. Defaults to 40.
--encoding | -e
The encoding of the message, such as json/utf-8.
--name | -n
The event name for the message.
--transport
The transport to use for publishing. Options are rest or realtime.
--client-id
A client ID to use when publishing 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 a plain text message:
ably channels publish my-channel "Hello, world!"Publish a JSON message:
ably channels publish my-channel '{"key": "value"}'Publish multiple messages with interpolation:
ably channels publish my-channel "Message {{.Count}} at {{.Timestamp}}" --count 10Publish with an event name:
ably channels publish my-channel "Hello" --name greetingPublish using the realtime transport:
ably channels publish my-channel "Hello" --transport realtimePublish with an event name using the --name option before the channel:
ably channels publish --name event my-channel '{"text":"Hello World"}'Publish messages at a controlled rate with timestamps:
ably channels publish --count 10 --delay 1000 my-channel "Message at {{.Timestamp}}"Publish a message with push notification extras:
ably channels publish my-channel '{"data":"Push notification","extras":{"push":{"notification":{"title":"Hello","body":"World"}}}}'Publish a message using an API key environment variable:
ABLY_API_KEY="YOUR_API_KEY" ably channels publish my-channel '{"data":"Simple message"}'Publish a message and output the result in JSON format:
ably channels publish my-channel "Hello World" --jsonPublish a message and output the result in formatted JSON:
ably channels publish my-channel "Hello World" --pretty-jsonSee also
- Channels — Explore all
ably channelscommands. - CLI reference — Full list of available commands.