question

station 1 lurie avatar image
station 1 lurie asked Phong Vu answered

How to keep the subscription alive so that it does not expire after 15 minutes ASP.NET NVC

My subscription was written in the Startup.cs file (with a hangfire dll) because I'm sending a message to clinters (using SignalR).

My problem is that when it is over 15 minutes the subscription is deleted.

I can run a timer every 14 minutes that will be re-subscribe or every 2 minutes to do renew.


What is the way to keep it always available?

sdk
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered

If you use the RingCentral .Net SDK to subscribe for notification, the subscription will be refreshed automatically as long as the access token (from the RestClient) is valid. If you don't use the RingCentral SDK, you have to implement a timer check the expiration time and call renew before it expires. See the code how it is handled by the SDK.

1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

station 1 lurie avatar image
station 1 lurie answered Phong Vu commented

Thank you

I use Nuget Ringcentral.Net Pubnub to subscribe.

So how long did the Token stay alive and how to keep it alive?

I know the token stayed for an hour.

1 comment
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Yes, currently the SDK does not do auto refresh for getting new access token. So you still have to manage that. We are considering to put the auto-refresh back (old C# SDK does) but this will take some time.

0 Likes 0 ·
station 1 lurie avatar image
station 1 lurie answered

Hi, I implementation the subscription according to RingCentral.Net.Pubnub.Subscription I also run a timer every 55 minutes to keep alive token.

My problem is after a few hours the token continued to refresh but the subscription lost.

I logged token and subscription state every 55 minutes ( when refreshing token)

1) log token state before refreshing.

refreshing token...

2) log subscription mode after refresh token.

3) log token state after refreshing.


The log file log_2019-08-01 - Copy.txt

My code is

 public void Init()
        {
            AsyncContext.Run(async () =>
            {
                _rc = await _rcEngine.GetRestClient();
            });

            Timer aTimer = new Timer();
            aTimer.Elapsed += OnTimedEvent;
            aTimer.Interval = 1000 * 60 * 55;
            //aTimer.Interval = 1000 * 20 * 1;
            aTimer.Enabled = true;
        }

        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            _logger.Info($"token: {_rc.token?.access_token} expires_in:{_rc.token?.expires_in}");
            
            AsyncContext.Run(async () =>
            {
                await _rc.Refresh();

                var subscriptions = await _rc.Restapi().Subscription().List();

                if (subscriptions.records.Any())
                {
                    foreach (var subscriptionsRecord in subscriptions.records)
                    {
                        _logger.Info($"eventFilters: {String.Join(", ",subscriptionsRecord.eventFilters)} " +
                                     $"expirationTime:{subscriptionsRecord.expirationTime} " +
                                     $"expiresIn:{subscriptionsRecord.expiresIn}");
                    }
                }
            });

            _logger.Info($"token: {_rc.token?.access_token} expires_in:{_rc.token?.expires_in}");
        }

1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered

It is hard to say why the subscription is lost w/o knowing how the entire app is implemented and run.

However, if you expect the subscription to run for long hours or days, Webhooks notification is a better choice. Please read this article and consider it.

1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys