Question

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

  • 4 June 2019
  • 4 replies
  • 2253 views

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?


4 replies

Userlevel 1

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.

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.

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}");
        }
Userlevel 1

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.

Reply