コード例 #1
0
        public async void StartSse()
        {
            try
            {
                var response = await _authApiClient.AuthenticateAsync();

                _log.Debug($"Auth service response pushEnabled: {response.PushEnabled}.");

                if (response.PushEnabled.Value)
                {
                    _sseHandler.Start(response.Token, response.Channels);
                    _backOff.Reset();
                    ScheduleNextTokenRefresh(response.Expiration.Value);
                }
                else
                {
                    StopSse();
                }

                if (response.Retry.Value)
                {
                    ScheduleNextTokenRefresh(_backOff.GetInterval());
                }
            }
            catch (Exception ex)
            {
                _log.Error($"StartSse: {ex.Message}");
            }
        }
コード例 #2
0
        public async Task <bool> StartSse()
        {
            try
            {
                var response = await _authApiClient.AuthenticateAsync();

                _log.Debug($"Auth service response pushEnabled: {response.PushEnabled}.");

                if (response.PushEnabled.Value && _sseHandler.Start(response.Token, response.Channels))
                {
                    _backOff.Reset();
                    ScheduleNextTokenRefresh(response.Expiration.Value);
                    _telemetryRuntimeProducer.RecordStreamingEvent(new StreamingEvent(EventTypeEnum.TokenRefresh, CalcularteNextTokenExpiration(response.Expiration.Value)));
                    return(true);
                }

                StopSse();

                if (response.Retry.Value)
                {
                    ScheduleNextTokenRefresh(_backOff.GetInterval());
                }
                else
                {
                    ForceCancellationToken();
                }
            }
            catch (Exception ex)
            {
                _log.Error($"StartSse: {ex.Message}");
            }

            return(false);
        }
コード例 #3
0
        private async Task <SyncResult> AttempSegmentSync(string name, long targetChangeNumber, FetchOptions fetchOptions, int maxRetries, int?retryDelayMs, bool withBackoff)
        {
            try
            {
                var remainingAttempts = maxRetries;

                if (withBackoff)
                {
                    _backOffSplits.Reset();
                }

                while (true)
                {
                    remainingAttempts--;
                    await _segmentFetcher.Fetch(name, fetchOptions);

                    if (targetChangeNumber <= _segmentCache.GetChangeNumber(name))
                    {
                        return(new SyncResult(true, remainingAttempts));
                    }
                    else if (remainingAttempts <= 0)
                    {
                        return(new SyncResult(false, remainingAttempts));
                    }

                    var delay = withBackoff ? _backOffSplits.GetInterval(inMiliseconds: true) : retryDelayMs.Value;
                    _wrapperAdapter.TaskDelay((int)delay).Wait();
                }
            }
            catch (Exception ex)
            {
                _log.Debug("Exception while AttempSplitsSync.", ex);
            }

            return(new SyncResult(false, 0));
        }
コード例 #4
0
        private async Task ConnectAsync()
        {
            try
            {
                _wrapperAdapter.TaskDelay(Convert.ToInt32(_backOff.GetInterval()) * 1000).Wait();

                _splitHttpClient = new SplitioHttpClient(new Dictionary <string, string> {
                    { "Accept", "text/event-stream" }
                });
                _cancellationTokenSource = new CancellationTokenSource();

                using (var response = await _splitHttpClient.GetAsync(_url, HttpCompletionOption.ResponseHeadersRead, _cancellationTokenSource.Token))
                {
                    UpdateFinishedConnection(finished: false);
                    try
                    {
                        using (var stream = await response.Content.ReadAsStreamAsync())
                        {
                            _log.Info($"Connected to {_url}");

                            UpdateStatus(connected: true);
                            _backOff.Reset();
                            DispatchConnected();
                            await ReadStreamAsync(stream);
                        }
                    }
                    catch (Exception ex)
                    {
                        _log.Error($"Error reading stream: {ex.Message}");
                        ReconnectAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error($"Error connecting to {_url}: {ex.Message}");
            }

            _log.Debug("Finished Event Source client ConnectAsync.");
            Disconnect();
            UpdateFinishedConnection(finished: true);
        }