Ejemplo n.º 1
0
        public MSSQLRelayListener(string connectionString,
                                  TimeSpan pollInterval,
                                  CancellationToken cancellationToken,
                                  int batchSize,
                                  bool deleteAfterSend,
                                  ISystemMetricsService metrics)
        {
            _connectionString  = connectionString;
            _intervalService   = new IntervalService(pollInterval, cancellationToken);
            _cancellationToken = cancellationToken;
            _batchSize         = batchSize;
            _deleteAfterSend   = deleteAfterSend;
            _metrics           = metrics;

            var stopwatch = new Stopwatch();

            _intervalService.Elapsed += (sender, e) =>
            {
                if (IsListening)
                {
                    _intervalService.Cancel(true);
                    stopwatch.Restart();
                    ReadAndFeed();
                    stopwatch.Stop();
                    metrics.LogCount("listeners.mssql-relay.feedTimeSeconds", Convert.ToInt32(stopwatch.Elapsed.TotalSeconds));

                    // Only continue the interval service if cancellation
                    // isn't in progress
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        _intervalService.Start();
                    }
                }
            };
        }