Beispiel #1
0
        private void Delete(List <AwsSqsMessage> messages, int idx, Stopwatch stopwatch)
        {
            if (idx == messages.Count)
            {
                stopwatch.Stop();
                lock (_received) {
                    _receives.Add(stopwatch.Elapsed.TotalSeconds);
                    _received.AddRange(messages.Select(x => x.Body));
                    _log.DebugFormat("consumed {0} at rate of {1:0.0}/s", _received.Count, _received.Count / _receives.Sum());
                }
                Receive();
                return;
            }
            var toBeDeleted = messages[idx];

            _client.Delete(toBeDeleted, new Result <AwsSqsResponse>()).WhenDone(r => {
                if (r.HasException)
                {
                    Exception = r.Exception;
                    return;
                }
                if (_stopped)
                {
                    return;
                }
                idx++;
                Delete(messages, idx, stopwatch);
            });
        }
Beispiel #2
0
            //--- Methods ---
            private IEnumerator <IYield> PollSqs(Result result)
            {
                _log.DebugFormat("polling SQS queue '{0}'", _queuename);
                while (!_isDisposed)
                {
                    Result <IEnumerable <AwsSqsMessage> > messageResult;
                    yield return(messageResult = _client.ReceiveMax(_queuename, new Result <IEnumerable <AwsSqsMessage> >()).Catch());

                    if (messageResult.HasException)
                    {
                        LogError(messageResult.Exception, "fetching messages");
                        result.Return();
                        yield break;
                    }
                    var messages = messageResult.Value;
                    if (!messages.Any())
                    {
                        result.Return();
                        yield break;
                    }
                    foreach (var msg in messages.Where(msg => !_cache.SetOrUpdate(msg.MessageId, _cacheTimer)))
                    {
                        try {
                            _log.DebugFormat("dispatching message '{0}' from queue '{1}'", msg.MessageId, _queuename);
                            _callback(msg);
                        } catch (Exception e) {
                            _log.Warn(
                                string.Format("dispatching message '{0}' from queue '{1}' threw '{2}': {3}",
                                              msg.MessageId,
                                              _queuename,
                                              e,
                                              e.Message
                                              ),
                                e
                                );
                            continue;
                        }
                        Result <AwsSqsResponse> deleteResult;
                        yield return(deleteResult = _client.Delete(msg, new Result <AwsSqsResponse>()).Catch());

                        if (deleteResult.HasException)
                        {
                            LogError(deleteResult.Exception, string.Format("deleting message '{0}'", msg.MessageId));
                        }
                        else
                        {
                            _cache.SetOrUpdate(msg.MessageId, _cacheTimer);
                        }
                    }
                }
                result.Return();
            }