When a channel becomes attached, either as a result of an explicit attach, or an implicit attach (typically following publish or subscribe on a channel), the Ably platform will broadcast messages to the client for that channel, so long as the client has permission to subscribe and the channel remains attached.
When subscribing to messages on a channel in the Ably realtime client libraries, what happens under the hood is:
- The channel is implicitly attached if not already attached
- A subscribe listener is registered in the client library channel object
So when attaching a channel (as in step 1), the client library will move the channel to the attaching state, and will request that the channel becomes attached within the Ably service for the current connection. Once attached, the Ably service confirms this attachment to the client and the channel becomes attached. For as long as that channel is attached and the client has subscribe permission on the channel, messages published on the channel will be streamed to the client.
However, registering listeners on a channel is an operation that only changes the state of the realtime library client, and is never communicated to Ably. As such, the Ably platform is unaware of how many listeners are registered and will always send messages to channels that are attached.
If you do not want to receive messages on channels that are attached, even if no listeners are registered, we recommend you detach the channel.