Use the ably channels subscribe command to subscribe to messages on one or more Ably Pub/Sub channels.
Synopsis
ably channels subscribe <channel-names> [options]Arguments
channel-names Required
One or more channel names to subscribe to.
Options
--cipher
A decryption key to use for decrypting messages on the channel.
--delta
Enable delta compression for messages. Defaults to false.
--sequence-numbers
Display sequence numbers for messages. Defaults to false.
--duration | -D
The duration in seconds to subscribe for before automatically unsubscribing.
--rewind
The number of messages to rewind when subscribing. Defaults to 0.
--client-id
A client ID to use when subscribing.
--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
Subscribe to a single channel:
ably channels subscribe my-channelSubscribe to multiple channels:
ably channels subscribe my-channel another-channelSubscribe for a specific duration:
ably channels subscribe my-channel --duration 60Subscribe with rewind to receive recent messages:
ably channels subscribe my-channel --rewind 10Subscribe with a cipher key for encrypted messages:
ably channels subscribe my-channel --cipher "my-secret-key"Subscribe with delta compression for bandwidth-efficient updates:
ably channels subscribe --delta my-channelSubscribe using an API key environment variable:
ABLY_API_KEY="YOUR_API_KEY" ably channels subscribe my-channelSubscribe and output messages in JSON format:
ably channels subscribe my-channel --jsonSubscribe and output messages in formatted JSON:
ably channels subscribe my-channel --pretty-jsonSee also
- Channels — Explore all
ably channelscommands. - CLI reference — Full list of available commands.