public override void PollQueue() { CloudStorageAccount account = QueueAccount; var queue = new MessageQueue <TMessage>(account); var frequencer = Frequencer; bool useDefaultTimeout = !Consumer.EstimatedTimeToProcessMessageBlock.HasValue; TimeSpan defaultTimeout = useDefaultTimeout ? TimeSpan.FromSeconds(1): Consumer.EstimatedTimeToProcessMessageBlock.Value; while (true) { try { var message = useDefaultTimeout ? queue.Dequeue() : queue.Dequeue(defaultTimeout); if (message != null) { try { Consumer.ProcessMessages(message); queue.Remove(message); } catch (Exception e) { OnProcessMessageLogException(message, e); } finally { frequencer.Decrease(); } } else { Thread.Sleep(frequencer.Current); } } catch (Exception e) { OnDequeueLogException(e); Thread.Sleep(5 * 1000); } } }
public override void PollQueue() { CloudStorageAccount account = QueueAccount; var queue = new MessageQueue <TMessage>(account); var queueRemover = GetQueueRemover(queue); IPollingFrequencer frequencer = Frequencer; bool useDefaultTimeout = !Consumer.EstimatedTimeToProcessMessageBlock.HasValue; TimeSpan defaultTimeout = useDefaultTimeout ? TimeSpan.FromSeconds(30) : Consumer.EstimatedTimeToProcessMessageBlock.Value; while (true) { try { var messages = useDefaultTimeout ? queue.Dequeue(Consumer.BlockSize).ToList() : queue.Dequeue(Consumer.BlockSize, defaultTimeout).ToList(); if (messages.Count > 0) { try { Consumer.ProcessMessagesGroup(queueRemover, messages); } catch (Exception e) { OnProcessMessageLogException(messages, e); } finally { frequencer.Decrease(); } } else { Thread.Sleep(frequencer.Current); } } catch (Exception e) { OnDequeueLogException(e); Thread.Sleep(5 * 1000); } } }