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

Cannot get RSocketResumableTransport running #116

Open
ayoUbuntu opened this issue Feb 15, 2021 · 5 comments
Open

Cannot get RSocketResumableTransport running #116

ayoUbuntu opened this issue Feb 15, 2021 · 5 comments
Labels

Comments

@ayoUbuntu
Copy link

ayoUbuntu commented Feb 15, 2021

I would like to enable my client to reconnect to my server in case the server restarts. I tried thus the example provided in rsocket-js/packages/rsocket-examples/src/ResumeExample.js. It seems however that even after restarting the server, no callback is ever made to resumableTransport.connect(). Nothing is caught within the onNext at the client side within the resumableTransport.connectionStatus().subscribe() block. For the record here's my piece of code :

rSocketClient: RSocketClient<any, Encodable>;  
responder;

ngOnInit(): void {
    const messageReceiver = payload => {
      console.log(payload);
    };
    this.responder = new EchoResponder(messageReceiver);
    
    const resumeToken = Buffer.from('helloworld');
    const bufferSize = 128;
    const sessionDurationSeconds = 20;
    const reconnectIntervalMillis = 5000;
    
    // Create an instance of a client
    const resumableTransport = new RSocketResumableTransport(
      // supplier of low-level transport
      () => new RSocketTcpClient({host: 'localhost', port: 7000}, BufferEncoders),
      {
        bufferSize, // max number of sent & pending frames to buffer before failing
        resumeToken, // unique identifier the session across connections
        sessionDurationSeconds,
      },
      BufferEncoders,
    );
    
    this.authenticationService.getLoggedInUser().subscribe(
      obj => {
        this.authToken = obj.principal;
        this.rSocketClient = new RSocketClient({
          serializers: {
            data: JsonSerializer,
            metadata: IdentitySerializer
          },
          setup: {
            payload: {
              data: this.authToken,
              metadata: String.fromCharCode('client-id'.length) + 'client-id'
            },
            // ms btw sending keepalive to server
            keepAlive: 1000,
            // ms timeout if no keepalive response
            lifetime: 10000,
            // format of `data`
            dataMimeType: 'application/json', // application/json
            // format of `metadata`
            metadataMimeType: 'message/x.rsocket.routing.v0', // message/x.rsocket.routing.v0
          },
          responder: this.responder,
          transport: resumableTransport,
        });
        
        let start = true;
        resumableTransport.connectionStatus().subscribe({
          onNext: status => {
            console.log('Resumable transport status changed: ' + status.kind);

            if (status.kind === 'NOT_CONNECTED') {
              if (!start) {
                console.log('Resumable transport disconnected, retrying...');
                setTimeout(() => resumableTransport.connect(), reconnectIntervalMillis);
              } else {
                start = false;
              }
            }
          },
          onSubscribe: subscription => {
            subscription.request(Number.MAX_SAFE_INTEGER);
          },
        });
      
        this.rSocketClient.connect().subscribe({
          onComplete: socket => {
            console.log('Connection successful');
          },
          onError: error => console.error(error)
        });
      },
      error => { console.log(error); }
    );
  }

Could someone help me please get this fixed. Thank you.

@SentryMan
Copy link

Were you able to make any progress on this?

@viglucci
Copy link
Member

viglucci commented Aug 3, 2021

Greetings @ayoUbuntu , @SentryMan , a new example has been added that demonstrates leveraging ResumableTransport.

Please take a look here and let us know if this resolve your questions.

@SentryMan
Copy link

Please take a look here and let us know if this resolve your questions.

You sure you have the right link there? that file hasn't been updated for quite a while. Perhaps you mean the file in this commit? 680976a. If so, that file doesn't look like it uses any RSocket Resume transport. It looks to me that it's just reconnecting on failure, not actually resuming.

@viglucci
Copy link
Member

viglucci commented Aug 3, 2021

@SentryMan ah, you are entirely correct. Apologies for the confusion.

@sudongyuer
Copy link

Were you able to make any progress on this? i have this issue too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants