internal async Task ListenLoop(CancellationToken ct) { var queueName = _queue.QueueName; var region = _queue.Region.SystemName; try { _messageProcessingStrategy.BeforeGettingMoreMessages(); var watch = new System.Diagnostics.Stopwatch(); watch.Start(); var req = new ReceiveMessageRequest { QueueUrl = _queue.Url, MaxNumberOfMessages = GetMaxBatchSize(), WaitTimeSeconds = 20 }; var sqsMessageResponse = await _queue.Client.ReceiveMessageAsync(req, ct); watch.Stop(); _messagingMonitor.ReceiveMessageTime(watch.ElapsedMilliseconds); var messageCount = sqsMessageResponse.Messages.Count; Log.Trace( "Polled for messages - Queue: {0}, Region: {1}, MessageCount: {2}", queueName, region, messageCount); foreach (var message in sqsMessageResponse.Messages) { HandleMessage(message); } } catch (InvalidOperationException ex) { Log.Trace( "Suspected no message in queue [{0}], region: [{1}]. Ex: {2}", queueName, region, ex); } catch (Exception ex) { var msg = string.Format( "Issue in message handling loop for queue {0}, region {1}", queueName, region); Log.Error(ex, msg); } }
internal void ListenLoop() { try { _messageProcessingStrategy.BeforeGettingMoreMessages(); var watch = new System.Diagnostics.Stopwatch(); watch.Start(); var sqsMessageResponse = _queue.Client.ReceiveMessage(new ReceiveMessageRequest { QueueUrl = _queue.Url, MaxNumberOfMessages = GetMaxBatchSize(), WaitTimeSeconds = 20 }); watch.Stop(); _messagingMonitor.ReceiveMessageTime(watch.ElapsedMilliseconds); var messageCount = sqsMessageResponse.Messages.Count; Log.Trace(string.Format("Polled for messages - Queue: {0}, MessageCount: {1}", _queue.QueueName, messageCount)); foreach (var message in sqsMessageResponse.Messages) { HandleMessage(message); } } catch (InvalidOperationException ex) { Log.Trace("Suspected no message in queue {0}. Ex: {1}", _queue.QueueName, ex); } catch (Exception ex) { Log.Error(ex, string.Format("Issue in message handling loop for queue {0}", _queue.QueueName)); } }