When attaching to a channel, you need to explicitly provide the channel name you are attaching to such as:
var channel = ably.channels.get('announcements')
channel.attach()
Attaching to more than one channel in a single operation is not possible, i.e. the following is not supported:
var channel = ably.channels.get('foo:*')
channel.attach()
/* attempting to attach to all channels matching the name foo:* will not work */
This is not possible for a number of reason:
- Attaching to unbounded number of channels in a single operation will not scale for your client devices or our servers terminating those connections
- Channels in our cluster are dynamically distributed across the available resources and move frequently. Each channel is largely autonomous and this is important to ensure the system remains reliable without a single point of failure or congestion. If a client were to subscribe to all channels matching a wildcard, then a connection would need to be maintained to every server in the cluster that could possibly be running a channel in case a channel is created that matches that wildcard. This does not scale.
- If you are subscribed to wildcard channels then it is impossible to offer the data delivery guarantees and quality of service we provide on channels because:
- At no point in time is there a way to deterministically know which channels a client is actually attached to
- If the client device becomes overloaded (can't keep up with the stream) or exceeds rate limits, our servers will have to selectively start dropping messages across random channels to ensure the client can continue to receive messages. Which messages should be dropped? How does a customer then work out which messages he/she missed?
However, because our connections are multiplexed thus allowing you to attach and detach from any channels dynamically over the same connection, it is of course possible to effectively subscribe to wildcard channels by attaching to channels as you need them.