Question

Subscriptions do not renew

  • 9 September 2022
  • 8 replies
  • 537 views

I'm using the RingCentral.net SDK. I use basically this code to monitor for my extension's calls:
=================
string s1 = "/restapi/v1.0/account/{0}/extension/~/presence?detailedTelephonyState=true&sipData=true";

string s2 = "/restapi/v1.0/account/{0}/telephony/sessions";

// replace the IDs in the above strings (not shown)

await restClient.PubNubExtension.Subscribe(new[] {s1, s2}, Device.ParseSubscription);

=================

After an hour the token for the RestClient needs renewing, so I renew this with:

await restClient.Refresh().ConfigureAwait(false);

Is there some best practice on how to use long lasting subscriptions? I'll happily share the non-working code that I'm doing, but I'm pretty sure it's wrong so I'd like to understand how to do it properly.



8 replies

Userlevel 1

What you did above is to refresh the access token so that you can continue using the restClient to call RingCentral APIs.

For PubNub subscription, it expires after 15 mins, but the SDK handle the renewal for you so you don't need to explicitly renew the subscription. All you need is to refresh the access token as you did above.

Thank you, @Phong Vu, for a quick response. So it sounds like it should be working already, but it is not.

In traces I see the subscription/renew happening every 13 minutes, so that's a good sign. But when the RestClient token refreshes then the subscriptions cease to work.

How can I investigate this further? Can think which direction I can go in to confirm any expectations?

I am the author of the RingCentral.NET SDK and I can help you on this.

By design, you just need to make sure that you always have a valid access token, then subscription will auto refresh 2 minutes before expiration.

I don't quite understand "await restClient.Refresh().ConfigureAwait(false);"

Shouldn't it be "await restClient.Refresh();" ?

Hi @Tyler Liu. Thank you for your help with this (And @Phong Vu too).

I have the subscriptions all working now, except for one situation. Please can I ask if this works for you because I'm thinking that it might be an issue with the SDK.

1) Start a client and do the token exchange

2) Set timers to renew tokens frequently enough (ie <15 mins)

3) Set up PubNub subscriptions

4) Prove that everything works and events are received

5) Hibernate your PC for >1 hour

6) When the PC returns from hibernation then everything appears to work, except no events are received (via PubNub).

I understand that some of the problems might possibly be down to my timers and token renewal. On the timer, it detects that the token is invalid and renews it again for a new token. Then it calls .Subscribe() again and the logs show that it works ("200") but still no events.

Before I go much further with this, are events after hibernation working for you (in any scenario)?

Thanks


I don't think subscriptions could survive a computer hibernate.

Because subscriptions expire in 15 minutes. When your computer wake up, the subscription already expired, there is not way to refresh. (the refresh should be done before the expiration.)


In that case, you may need to re-create the subscriptions.

Hi @Tyler Liu. Thanks. Sorry, yes I should have been clearer. We detect the outage (ie token failure) and destroy the restclient and pubnubextension and create new ones. Using the new objects we . subscribe and get a successful response but not events follow.


Your response makes me think that somehow we are not destroying the old objects sufficiently well or that it must be some other fault in terms of how we’re handling the objects.


In principle if we’re creating all new objects after the unhibernate then it really ought to work ok, right?

It should just work if you create new objects instead. Please try again and update me.

@Tyler Liu I got to the bottom of this. When the machine comes out of hibernation, then the DNS service isn't fully working, and the RingCentral requests fail. We've seen the exceptions and thought it was game over. But it's not. When the network returns fully, then we can refresh the token and carry on. The PubNub connection still wobbles over this but ultimately it works within a refresh cycle (ie within 15 minutes).

Not sure if this helps. But I thought it could be useful to write these findings in case it helps someone else.

Reply