-
Notifications
You must be signed in to change notification settings - Fork 107
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
Possibility to set last message ID on first subscribe #44
Conversation
I think this is a very necessary feature. |
This feature can theoretically make users misuse Centrifugo - i.e. only relying on Centrifugo to recover missed messages - and this is in general bad practice because Centrifugo does not have any guarantees about that - only best effort. On the other hand some apps that do not require much performance and reliability can benefit. @Inpassor thanks for feedback on this, hope we collect more opinions with time. |
In my opinion, in any case, you rely on a centrifuge to restore messages. But there will be a choice - to restore all available messages, or just missed. Don't care about guarantees, at least something will be recovered. |
Sorry to drag this back to life, but coming from NCHAN this seems like a really useful missing feature. The way I used it in NCHAN was like...
... and we're only talking a few seconds of possible missed messages while the page loads, so of course we'll still have them with any reasonable history limits configured. Hope this can get merged into v2 at some point! Until then, any suggestions on accomplishing something like this for now? |
@gazugafan hello!
Does this mean that message IDs in your database and NCHAN cache match? Centrifugo act more like Kafka when incremental message offset in channel (may call it ID I suppose) assigned internally by Centrifugo itself at the moment of publication. Though it's pretty possible to get a last offset for a channel in Centrifugo and will be available as part of API soon in Centrifugo v3. |
Yes, the message ID in the NCHAN cache ends up matching what's stored in the application database. This is because NCHAN returns the new message ID when you publish a message. So, everytime we publish a message from the backend, we get the message ID and immediately save it back to the database.
This seems to be the missing piece of the puzzle. There's currently no way to get the last offset for a channel after publishing? |
It's also possible to return a published offset in Centrifugo (looks like one more thing worth adding to v3). Some caveats to be aware of:
Currently no. If you feel that this all can be a good fit for your app could you open an issue in Centrifugo? Maybe this is possible to introduce in terms of Centrifugo v2 - not sure which version to aim at the moment. But this all seems very reasonable to have. |
This is preferable!
Makes sense!
Will do, thanks so much! ❤ |
Closing in favour of newly created issue. Code here is for v1 so should be rewritten anyway. |
This pull request contains code to provide last message ID manually on first subscribe to channel to restore missed messages on page open. This way it's possible to save last message ID in localStorage and then restore from that position. I.e. sth like:
Not sure that its needed though... Because on first subscribe history should be loaded from backend. But in theory this is interesting. Open for discussion.