Exemplo n.º 1
0
 public void StartManualPolling(
     String checkpointTokenFrom,
     Int32 bufferSize  = 4000,
     String pollerName = "CommitPollingClient")
 {
     _bufferSize             = bufferSize;
     _checkpointTokenCurrent = checkpointTokenFrom;
     LastException           = null;
     //prepare single poller thread.
     CreateTplChain();
     _pollerThread = new Thread(PollerFunc);
     _pollerThread.IsBackground = true;
     _pollerThread.Name         = pollerName;
     _pollerThread.Start();
     MetricsHelper.SetCommitPollingClientBufferSize(pollerName, () => GetClientBufferSize());
 }
        private void RegisterHealthChecks(string pollerName)
        {
            MetricsHelper.SetCommitPollingClientBufferSize(pollerName, () => GetClientBufferSize());
            //Set health check for polling
            HealthChecks.RegisterHealthCheck("Polling-" + pollerName, () =>
            {
                if (Status == CommitPollingClientStatus.Stopped)
                {
                    //poller is stopped, system healty
                    return(HealthCheckResult.Healthy("Automatic polling stopped"));
                }
                else if (Status == CommitPollingClientStatus.Faulted || LastException != null)
                {
                    //poller is stopped, system healty
                    var exceptionText = (LastException != null ? LastException.ToString() : "");
                    exceptionText     = exceptionText.Replace("{", "{{").Replace("}", "}}");
                    return(HealthCheckResult.Unhealthy("Faulted (exception in consumer): " + exceptionText));
                }
                var elapsed = DateTime.UtcNow - _innerClient.LastActivityTimestamp;
                if (elapsed.TotalMilliseconds > 5000)
                {
                    //more than 5 seconds without a poll, polling probably is stopped
                    return(HealthCheckResult.Unhealthy(String.Format("poller stuck, last polling {0} ms ago", elapsed)));
                }

                return(HealthCheckResult.Healthy("Poller alive"));
            });
            //Now register health check for the internal NES poller, to diagnose errors in polling.
            HealthChecks.RegisterHealthCheck("Polling internal errors: ", () =>
            {
                if (_innerClient != null && !String.IsNullOrEmpty(_innerClient.LastPollingError))
                {
                    return(HealthCheckResult.Unhealthy($"Inner NES poller has error: {_innerClient.LastPollingError}"));
                }
                return(HealthCheckResult.Healthy("Inner NES Poller Ok"));
            });
        }