rsocket-js
rsocket-js copied to clipboard
Cannot get RSocketResumableTransport running
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.
Were you able to make any progress on this?
~~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.~~
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? https://github.com/rsocket/rsocket-js/commit/680976ab2ec7ca95aa526cff903739c99997d0d. 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.
@SentryMan ah, you are entirely correct. Apologies for the confusion.
Were you able to make any progress on this? i have this issue too