However, once the client has been disconnected for more than 2 minutes, the client library moves into the suspended state indicating that all connection state is lost. As such, all channels are automatically suspended at this point too indicating that channel continuity is not possible. Once the connection is reestablished, the client library will reattach the suspended channels automatically and emit an attached event with the resumed flag set to false. This ensures that as a developer, you can listen for attached events and check the resumed flag to see if a channel resumed fully and no messages were lost (when resumed is true), or the channel attached but could not resume (when resumed is false). If channel continuity is not possible, then typically if historical messages are important to you, you would use the history API to retrieve all older messages, with the untilAttach flag set to true. Find out more about nonfatal channel errors and how to handle them.
Commonly asked questions
- How many messages will you store whilst a client is disconnected?
There is no hard limit so we will in almost all circumstances be able to keep all messages for two minutes.
- What happens if messages cannot be replayed or the connection cannot be recovered?
If the connection is not able to be recovered, Ably notifies the client and the client will reattached the channels and emit an attached event with the resumed flag set to false. As a developer, this gives you certainty and predictability you need to build a reliable application. If a channel is not resumed successfully (i.e. Ably cannot guarantee you have not missed messages since you were last attached), then you will need to decide what action you may take, including potentially retrieving the history of that channel via our history API.