Option to recover missed messages based on last message ID #42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New feature here –
recover
channel option. This inspired byLast-Event-ID
mechanism from Eventsource protocol (http://www.w3.org/TR/2012/WD-eventsource-20120426/). This is backwards compatible change and option turned off by default.First let's describe motivation. We live not in ideal world and network connection can disappear sometimes. While client offline some messages could be sent into channel and when client goes online those messages are lost. Centrifugo can help to automatically recover reasonable amount of missed messages.
There are still cases when Centrifugo can't help – for example if client was disconnected for a week... In this situation thousands of messages could travel through channel and client must recover its state with application frontend/backend code help.
But when connection disappeared for a short amount of time then Centrifugo can automatically recover missed messages when client resubscribes on channel. For this purpose client provides last message UID seen when resubscribing and Centrifugo automatically tries to recover missed messages from message history.
New
recover
option must be used in combination withhistory_size
andhistory_lifetime
. Bothhistory_size
andhistory_lifetime
must be reasonably configured andrecover
turned on for channel (for all channels or for namespace - you decide).Note that sometimes your clients don't need to get missed messages at all. This depends on nature of real-time messages you publish. For example you really don't need missed messages in case of frequently updated counter with actual value in message.
So developer must think wisely when he wants to enable this mechanism. For example it can be reasonable to enable it if you show comments on page in real-time. In this case when your client goes online it receives all missed comments automatically from Centrifugo message history.
Also note that there are other possible solutions to get missed messages based on your application code - you can still manually retrieve message history from Centrifugo or from your application backend.
This option required introducing new client protocol fields (in subscribe message and response to subscribe request).
Javascript client with support of this feature is in separate branch at moment https://github.com/centrifugal/centrifuge-js/tree/recover
Example of config: