How can I check session is connected or not (is session active/connected)? in solclientjs
Hi All,
I do have few queries regarding the session lifespan in solclientjs lib.
- How can I check (periodically) session is active/connected or not?
- When connected using oauth2 and as soon as token expires then I see the session get disconnected, how does the client application get notified for disconnection instantly? I see it does reconnect for number of reconnect retries, is there any way that client can be notified instantly?
Thanks
Prashant
Answers
-
Hi @prashantk2000 - I am sure you might have already checked out the nodejs samples; if not, please refer to any of the nodejs samples in the tutorials sections.
sample.session.on(solace.SessionEventCode.UP_NOTICE, function (sessionEvent) { sample.log('=== Successfully connected and ready to start the message consumer. ==='); sample.startConsume(); }); sample.session.on(solace.SessionEventCode.CONNECT_FAILED_ERROR, function (sessionEvent) { sample.log('Connection failed to the message router: ' + sessionEvent.infoStr + ' - check correct parameter values and connectivity!'); }); sample.session.on(solace.SessionEventCode.DISCONNECTED, function (sessionEvent) { sample.log('Disconnected.'); sample.consuming = false; if (sample.session !== null) { sample.session.dispose(); sample.session = null; } });
The Solace Node.js API communicates changes in status and results of connect and subscription calls through emitting session events with certain event names. The client can register callbacks to receive these
SessionEvent
and take necessary action. And you can control session connection-related parameters viaSessionProperties
yourcreateSession
call.I hope this helps - if your query is different, please elaborate.
1 -
Thanks @giri ,
I have few more queries as we are using OAuth2 Authentication for publishing/consuming,
- Session gets disconnected when the accessToken expires and it does the reconnect up to the reconnectRetries count but with same token which is already expired, is there way that we can pass the fresh JWT token for reconnect? I see it sends DOWN_ERROR after the reconnectRetries count exhaust, so do we require to call disconnect and dispose there?
- What would be the right approach to handle the session disconnection after token expires. Any suggestions?
Thanks,
Prashant
0 -
Hi @prashantk2000,
Please check out Session.updateAuthenticationOnReconnect() which was added in v10.10.0
Hope that helps!
1 -
Thanks a lot @marc for sharing this, we able to resolve connectivity issue.
0