private async Task ListenLoopExecuted(Queue <Func <Task> > actions, IMessageProcessingStrategy messageProcessingStrategy) { var initalActionCount = actions.Count; var timeoutSeconds = 10 + (initalActionCount / 100); var timeout = new TimeSpan(0, 0, timeoutSeconds); var stopwatch = Stopwatch.StartNew(); while (actions.Any()) { var batch = GetFromFakeSnsQueue(actions, messageProcessingStrategy.AvailableWorkers); foreach (var action in batch) { messageProcessingStrategy.StartWorker(action); } if (!actions.Any()) { break; } messageProcessingStrategy.AvailableWorkers.ShouldBeGreaterThanOrEqualTo(0); await messageProcessingStrategy.WaitForAvailableWorkers(); messageProcessingStrategy.AvailableWorkers.ShouldBeGreaterThan(0); stopwatch.Elapsed.ShouldBeLessThanOrEqualTo(timeout, $"ListenLoopExecuted took longer than timeout of {timeoutSeconds}s, with {actions.Count} of {initalActionCount} messages remaining"); } }
private async Task ListenLoopExecuted(Queue <Func <Task> > actions, IMessageProcessingStrategy messageProcessingStrategy) { var initalActionCount = actions.Count; var timeoutSeconds = 10 + (initalActionCount / 100); var timeout = new TimeSpan(0, 0, timeoutSeconds); var stopwatch = Stopwatch.StartNew(); while (actions.Any()) { var batch = GetFromFakeSnsQueue(actions, messageProcessingStrategy.AvailableWorkers); foreach (var action in batch) { messageProcessingStrategy.StartWorker(action); } if (!actions.Any()) { break; } Assert.That(messageProcessingStrategy.AvailableWorkers, Is.GreaterThanOrEqualTo(0)); await messageProcessingStrategy.WaitForAvailableWorkers(); Assert.That(messageProcessingStrategy.AvailableWorkers, Is.GreaterThan(0)); if (stopwatch.Elapsed > timeout) { var message = string.Format("ListenLoopExecuted took longer than timeout of {0}s, with {1} of {2} messages remaining", timeoutSeconds, actions.Count, initalActionCount); Assert.Fail(message); } } }
private static async Task ListenLoopExecuted( Queue <Func <Task> > actions, IMessageProcessingStrategy messageProcessingStrategy) { var initalActionCount = (double)actions.Count; var timeout = MinTaskDuration + TimeSpan.FromMilliseconds(initalActionCount / 100); var stopwatch = Stopwatch.StartNew(); while (actions.Any()) { var batch = GetFromFakeSnsQueue(actions, messageProcessingStrategy.MaxConcurrency); if (batch.Count < 1) { break; } foreach (var action in batch) { (await messageProcessingStrategy.StartWorkerAsync(action, CancellationToken.None)).ShouldBeTrue(); } messageProcessingStrategy.MaxConcurrency.ShouldBeGreaterThanOrEqualTo(0); (await messageProcessingStrategy.WaitForAvailableWorkerAsync()).ShouldBeGreaterThan(0); messageProcessingStrategy.MaxConcurrency.ShouldBeGreaterThan(0); } }
public SqsNotificationListener( SqsQueueBase queue, IMessageSerializationRegister serializationRegister, IMessageMonitor messagingMonitor, ILoggerFactory loggerFactory, IMessageContextAccessor messageContextAccessor, Action <Exception, Amazon.SQS.Model.Message> onError = null, IMessageLockAsync messageLock = null, IMessageBackoffStrategy messageBackoffStrategy = null) { _queue = queue; _messagingMonitor = messagingMonitor; onError = onError ?? DefaultErrorHandler; _log = loggerFactory.CreateLogger("JustSaying"); _messageProcessingStrategy = new DefaultThrottledThroughput(_messagingMonitor); _messageHandlerWrapper = new MessageHandlerWrapper(messageLock, _messagingMonitor); _messageDispatcher = new MessageDispatcher( _queue, serializationRegister, messagingMonitor, onError, _handlerMap, loggerFactory, messageBackoffStrategy, messageContextAccessor); Subscribers = new Collection <ISubscriber>(); if (messageBackoffStrategy != null) { _requestMessageAttributeNames.Add(MessageSystemAttributeName.ApproximateReceiveCount); } }
public SqsNotificationListener(SqsQueueBase queue, IMessageSerialisationRegister serialisationRegister, IMessageMonitor messagingMonitor, Action <Exception, Amazon.SQS.Model.Message> onError = null, IMessageLock messageLock = null) { _queue = queue; _serialisationRegister = serialisationRegister; _messagingMonitor = messagingMonitor; _onError = onError ?? ((ex, message) => { }); _handlers = new Dictionary <Type, List <Func <Message, bool> > >(); _messageProcessingStrategy = new MaximumThroughput(); _messageLock = messageLock; }
public Mail2BugEngine(Config.InstanceConfig configInstance, MailboxManagerFactory mailboxManagerFactory) { _config = configInstance; Logger.InfoFormat("Initializing MailboxManager"); _mailboxManager = mailboxManagerFactory.CreateMailboxManager(_config.EmailSettings); Logger.InfoFormat("Initializing WorkItemManager"); _messageProcessingStrategy = new Lazy <IMessageProcessingStrategy>(InitProcessingStrategy); _messageProcessingStrategyImmediate = InitProcessingStrategy(); }
public Mail2BugEngine(Config.InstanceConfig configInstance, MailboxManagerFactory mailboxManagerFactory) { _config = configInstance; Logger.Info("Initializing MailboxManager"); _mailboxManager = mailboxManagerFactory.CreateMailboxManager(_config.EmailSettings); Logger.Info("Initializing WorkItemManager"); _messageProcessingStrategy = new Lazy<IMessageProcessingStrategy>(InitProcessingStrategy); _messageProcessingStrategyImmediate = InitProcessingStrategy(); }
// ToDo: This should not be here. public SqsNotificationListener WithMaximumConcurrentLimitOnMessagesInFlightOf( int maximumAllowedMesagesInFlight, TimeSpan?startTimeout = null) { var options = new ThrottledOptions() { MaxConcurrency = maximumAllowedMesagesInFlight, StartTimeout = startTimeout ?? Timeout.InfiniteTimeSpan, Logger = _log, MessageMonitor = _messagingMonitor, }; _messageProcessingStrategy = new Throttled(options); return(this); }
public SqsNotificationListener( SqsQueueBase queue, IMessageSerialisationRegister serialisationRegister, IMessageMonitor messagingMonitor, Action <Exception, Amazon.SQS.Model.Message> onError = null, IMessageLock messageLock = null) { _queue = queue; _messagingMonitor = messagingMonitor; onError = onError ?? ((ex, message) => { }); _messageProcessingStrategy = new DefaultThrottledThroughput(_messagingMonitor); _messageHandlerWrapper = new MessageHandlerWrapper(messageLock, _messagingMonitor); _messageDispatcher = new MessageDispatcher(queue, serialisationRegister, messagingMonitor, onError, _handlerMap); Subscribers = new Collection <ISubscriber>(); }
public Mail2BugEngine(Config.InstanceConfig configInstance) { _config = configInstance; Logger.InfoFormat("Initalizing MailboxManager"); _mailboxManager = MailboxManagerFactory.CreateMailboxManager(_config.EmailSettings); Logger.InfoFormat("Initializing WorkItemManager"); IWorkItemManager workItemManager; if (configInstance.TfsServerConfig.SimulationMode) { Logger.InfoFormat("Working in simulation mode. Using WorkItemManagerMock"); workItemManager = new WorkItemManagerMock(_config.WorkItemSettings.ConversationIndexFieldName); } else { Logger.InfoFormat("Working in standard mode, using TFSWorkItemManager"); workItemManager = new TFSWorkItemManager(_config); } Logger.InfoFormat("Initializing MessageProcessingStrategy"); _messageProcessingStrategy = new SimpleBugStrategy(_config, workItemManager); }
public SqsNotificationListener WithMessageProcessingStrategy(IMessageProcessingStrategy messageProcessingStrategy) { _messageProcessingStrategy = messageProcessingStrategy; return(this); }
// ToDo: This should not be here. public SqsNotificationListener WithMaximumConcurrentLimitOnMessagesInFlightOf(int maximumAllowedMesagesInFlight) { _messageProcessingStrategy = new Throttled(maximumAllowedMesagesInFlight, _messagingMonitor); return(this); }
private async Task ListenLoopExecuted(Queue<Func<Task>> actions, IMessageProcessingStrategy messageProcessingStrategy) { var initalActionCount = actions.Count; var timeoutSeconds = 10 + (initalActionCount / 100); var timeout = new TimeSpan(0, 0, timeoutSeconds); var stopwatch = Stopwatch.StartNew(); while (actions.Any()) { var batch = GetFromFakeSnsQueue(actions, messageProcessingStrategy.AvailableWorkers); foreach (var action in batch) { messageProcessingStrategy.StartWorker(action); } if (!actions.Any()) { break; } Assert.That(messageProcessingStrategy.AvailableWorkers, Is.GreaterThanOrEqualTo(0)); await messageProcessingStrategy.WaitForAvailableWorkers(); Assert.That(messageProcessingStrategy.AvailableWorkers, Is.GreaterThan(0)); if (stopwatch.Elapsed > timeout) { var message = string.Format("ListenLoopExecuted took longer than timeout of {0}s, with {1} of {2} messages remaining", timeoutSeconds, actions.Count, initalActionCount); Assert.Fail(message); } } }