internal void LongPollSqs(SqsPollingClientSettings settings) { var failCounter = 0; while (true) { IEnumerable <SqsMessage> messages; try { messages = _container._client.ReceiveMessages(settings.QueueName, settings.LongPollInterval, settings.MaxNumberOfMessages); failCounter = 0; } catch (Exception e) { LogError(e, string.Format("ReceiveMessages (fail count: {0:#,##0})", ++failCounter)); AsyncUtil.Sleep(settings.WaitTimeOnError); continue; } if (_isDisposed) { break; } if (messages.None()) { continue; } try { settings.Callback(messages); } catch (Exception e) { LogError(e, "callback failed"); } } }
//--- Methods --- /// <summary> /// Start listening for SQS messages with the provided settings. /// </summary> /// <param name="settings">Polling settings.</param> /// <returns>Object to dispose listener when no longer needed.</returns> public IDisposable Listen(SqsPollingClientSettings settings) { if(settings == null) { throw new ArgumentNullException("settings"); } var listener = new Listener(this); lock(_listeners) { _listeners.Add(listener); } AsyncUtil.Fork(() => listener.LongPollSqs(settings)); return listener; }
//--- Methods --- /// <summary> /// Start listening for SQS messages with the provided settings. /// </summary> /// <param name="settings">Polling settings.</param> /// <returns>Object to dispose listener when no longer needed.</returns> public IDisposable Listen(SqsPollingClientSettings settings) { if (settings == null) { throw new ArgumentNullException("settings"); } var listener = new Listener(this); lock (_listeners) { _listeners.Add(listener); } AsyncUtil.Fork(() => listener.LongPollSqs(settings)); return(listener); }
internal void LongPollSqs(SqsPollingClientSettings settings) { var failCounter = 0; while(true) { IEnumerable<SqsMessage> messages; try { messages = _container._client.ReceiveMessages(settings.QueueName, settings.LongPollInterval, settings.MaxNumberOfMessages); failCounter = 0; } catch(Exception e) { LogError(e, string.Format("ReceiveMessages (fail count: {0:#,##0})", ++failCounter)); AsyncUtil.Sleep(settings.WaitTimeOnError); continue; } if(_isDisposed) { break; } if(messages.None()) { continue; } try { settings.Callback(messages); } catch(Exception e) { LogError(e, "callback failed"); } } }