Exemplo n.º 1
0
        public void Send(Func <LogCastDocument> documentFactory)
        {
            var job = new LogCastMessageFactory(documentFactory,
                                                _options.EnableSelfDiagnostics ? DateTime.Now : (DateTime?)null);

            _countEvent.Increase();
            _queue.Add(job);
        }
Exemplo n.º 2
0
        protected virtual bool ConsumeDocument(int threadId, LogCastMessageFactory logCastMessageFactory, int timeoutMsec, int dropCount, int retryCount, out int newRetries)
        {
            string    message = null;
            Stopwatch sw      = null;

            newRetries = 0;

            //retry cycle
            while (_queue.Count <= _options.Throttling)
            {
                //if this is not retry, then create a message to send
                if (message == null)
                {
                    sw      = Stopwatch.StartNew();
                    message = logCastMessageFactory.Create(dropCount, retryCount);
                }

                var endpoint = GetEndpoint();

                var exception = SendHandled(endpoint, message, timeoutMsec);
                if (exception == null)
                {
                    return(true);
                }

                if (SkipRetry(exception))
                {
                    _fallbackLogger.Write("DROPPING by SKIPPING retry",
                                          Format(exception, message),
                                          Stats(threadId, dropCount + 1, retryCount + newRetries, _queue.Count));
                    return(false);
                }

                if (sw.Elapsed >= _options.RetryTimeout)
                {
                    _fallbackLogger.Write($"DROPPING by RetryTimeout ({_options.RetryTimeout})",
                                          Format(exception, message),
                                          Stats(threadId, dropCount + 1, retryCount + newRetries, _queue.Count));
                    return(false);
                }

                ++newRetries;

                //To skip over-intensive retry
                Thread.Sleep(100);
            }

            // We expect a lot of messages with Throttling failure so log only some of them
            if (dropCount % 1000 == 0)
            {
                _fallbackLogger.Write($"DROPPING by Throttling ({_options.Throttling})",
                                      Stats(threadId, dropCount + 1, retryCount + newRetries, _queue.Count));
            }
            return(false);
        }