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 theChannels 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
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:
customercustomer:tracking-idcustomer:order:update
*.
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
| Rule | Description |
|---|---|
| Persist last message | If 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 messages | If 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. |
| Rule | Description |
|---|---|
| Identified | If enabled, clients will not be permitted to use matching channels unless they are identified (they have an assigned client ID). |
| TLS only | If enabled, only clients who have connected to Ably over TLS will be allowed to use matching channels. |
- Sign in to your Ably account.
- Select an app.
- Go to Settings tab.
- Click Add new rule.
- Select channel name or namespace to apply rules to.
- Check required rules.
Next steps
- Learn how to publish messages
- Learn how to subscribe to messages
- Explore channel options
- Understand message format
