Skip to main content
Channels are used to separate messages into different topics. They are the building block of creating a realtime application using the publish-subscribe pattern. Channels are also the unit of security and scalability. Clients should only ever be provided the capabilities for channels that they should have access to. Messages contain the data that a client is communicating, such as the contents of an individual chat message, or an event that has occurred, such as updated financial information. With Pub/Sub you create a channel, subscribe to it, and then publish messages to it. Most other Ably features utilize channels, or a group of channels, to provide additional functionality to your realtime applications.

Use a channel

To get started with implementing any feature, a client must first create or retrieve an instance of a channel. A channel is created, or an existing channel is retrieved from the Channels collection. You can only connect to one channel in a single operation. Channels are identified by their unique name. The following restrictions apply to when naming a channel:
  • Channel names are case sensitive
  • They can’t start with [ or :
  • They can’t be empty
  • They can’t contain newline characters
While Ably doesn’t limit the length of channel names, keeping them under 2048 characters is recommended, since some older browsers have trouble with long URLs. Use the get() method to create or retrieve a channel instance:

Channel namespaces

Channels can be grouped together into a namespace. This enables you to apply operations to a namespace rather than each individual channel within it. A namespace is the first part of a channel name up to the first colon (:). If a channel name does not contain a colon, the namespace is the entire channel name. For example, the following channels are all part of the ‘customer’ namespace:
  • customer
  • customer:tracking-id
  • customer:order:update
Channel namespaces have the same restrictions as those listed for channels. Additionally they cannot contain the wildcard character *. Use channel namespaces to apply operations to all channels within that group, such as capabilities, channel rules and integrations.

Channel options

Channel options are used to customize the functionality of channels. This includes enabling features such as encryption and deltas, or for a client to retrieve messages published prior to it attaching to a channel using rewind.

Channel rules

Channel rules can be used to enforce settings for specific channels, or channel namespaces. They can be broadly categorized into three different types:
  • For message storage
  • For client security and identification
  • To enable features for a channel or namespace
The channel rules related to message storage are:
RuleDescription
Persist last messageIf enabled, the very last message published on a channel will be stored for a year. This message is retrievable using rewind by attaching to the channel with rewind=1.
Persist all messagesIf enabled, all messages published on a channel will be stored according to the storage rules for your account. This is 24 hours for free accounts and 72 hours for paid accounts. Messages stored in this manner are accessible using history.
The channel rules related to security and client identity are:
RuleDescription
IdentifiedIf enabled, clients will not be permitted to use matching channels unless they are identified (they have an assigned client ID).
TLS onlyIf enabled, only clients who have connected to Ably over TLS will be allowed to use matching channels.
To set a channel rule in the Ably dashboard:
  1. Sign in to your Ably account.
  2. Select an app.
  3. Go to Settings tab.
  4. Click Add new rule.
  5. Select channel name or namespace to apply rules to.
  6. Check required rules.

Next steps

Build docs developers (and LLMs) love