Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to recover missed messages based on last message ID #42

Merged
merged 9 commits into from
Dec 2, 2015

Conversation

FZambia
Copy link
Member

@FZambia FZambia commented Nov 29, 2015

New feature here – recover channel option. This inspired by Last-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 with history_size and history_lifetime. Both history_size and history_lifetime must be reasonably configured and recover 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:

{
  "web_password": "password",
  "web_secret": "secret",
  "secret": "secret",
  "namespaces": [
    {
      "name": "public",
      "history_size": 100,
      "history_lifetime": 300,
      "recover": true
    }  
  ]
}

FZambia added a commit that referenced this pull request Dec 2, 2015
Option to recover missed messages based on last message ID
@FZambia FZambia merged commit b91e83b into master Dec 2, 2015
@FZambia FZambia deleted the last_uid branch December 14, 2015 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant