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

How to pass recover option when subscribe to a channel #115

Closed
lsc20051426 opened this issue Jul 22, 2020 · 4 comments
Closed

How to pass recover option when subscribe to a channel #115

lsc20051426 opened this issue Jul 22, 2020 · 4 comments

Comments

@lsc20051426
Copy link

lsc20051426 commented Jul 22, 2020

https://centrifugal.github.io/centrifugo/transports/recovery/
Is there a way to pass the recover from client(as mention in above link) to fetching some history messages?

When server receives subscribe command with boolean flag recover set to true and offset, epoch set to values last seen by a client (see SubscribeRequest type in protocol definitions) it can try to find all missed publications from history cache. Recovered publications will be passed to client in subscribe Reply in correct order, and your publication handler will be automatically called to process each missed message.

in Centrifuge-JS:

options = {recover: true,  offset: 6}
centrifuge.subscribe("channel", options, callback);

probably?
or is there are some other ways to do it?

@FZambia
Copy link
Member

FZambia commented Jul 23, 2020

@lsc20051426 hi, description in docs is about internal protocol which is only used for automatic recovery in case of network disconnects at moment.

But I understand what you mean – actually there is rather old open pull request #44 that allows to do what you are describing. But that pr was made for version 1 of centrifuge-js, so not actual at moment.

I did not merge it because I have not found enough motivation and live use case to extend API. Could you describe how you are planning to use this? Are you planning to save offset in localStorage? Why do you want this instead of asking database about actual state?

@lsc20051426
Copy link
Author

you are right. we save offset in localStorage.

  • Give the offset when subscribe.
  • save offset for channel when receiving a new message in local.

Here are some hacks for js code(just example):

-    value: function subscribe(channel, events) {
+    value: function subscribe(channel, events, options) {
       var currentSub = this._getSub(channel);
       if (currentSub !== null) {
         currentSub._setEvents(events);
@@ -1995,6 +1995,9 @@ var Centrifuge = exports.Centrifuge = function (_EventEmitter) {
         return currentSub;
       }
       var sub = new _subscription2.default(this, channel, events);
+      sub._recover = options.recover;
+      sub._recoverable = options.recoverable;
+      this._lastOffset[channel] = options.offset;
       this._subs[channel] = sub;
       sub.subscribe();
       return sub;

@FZambia
Copy link
Member

FZambia commented Jul 30, 2020

Can you give a bit more use case description? Why do you need this instead of asking initial state from main application database?

@FZambia
Copy link
Member

FZambia commented Nov 5, 2021

@FZambia FZambia closed this as completed Nov 5, 2021
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

No branches or pull requests

2 participants