public Task StartReceive(CancellationToken cancellationToken = default) { maximumConcurrency = limitations.MaxConcurrency; concurrencyLimiter = new SemaphoreSlim(maximumConcurrency, maximumConcurrency); messagePumpCancellationTokenSource = new CancellationTokenSource(); messageProcessingCancellationTokenSource = new CancellationTokenSource(); circuitBreaker = new RepeatedFailuresOverTimeCircuitBreaker("AzureStorageQueue-MessagePump", TimeToWaitBeforeTriggering, ex => criticalErrorAction("Failed to receive message from Azure Storage Queue.", ex, messageProcessingCancellationTokenSource.Token)); Logger.DebugFormat($"Starting MessageReceiver {Id} with max concurrency: {0}", maximumConcurrency); var receiverConfigurations = MessagePumpHelpers.DetermineReceiverConfiguration(receiveBatchSize, degreeOfReceiveParallelism, maximumConcurrency); messagePumpTasks = new Task[receiverConfigurations.Count]; for (var i = 0; i < receiverConfigurations.Count; i++) { var backoffStrategy = new BackoffStrategy(peekInterval, maximumWaitTime); var batchSizeForReceive = receiverConfigurations[i].BatchSize; // Task.Run() so the call returns immediately instead of waiting for the first await or return down the call stack messagePumpTasks[i] = Task.Run(() => PumpMessagesAndSwallowExceptions(batchSizeForReceive, backoffStrategy, messagePumpCancellationTokenSource.Token), CancellationToken.None); } return(Task.CompletedTask); }
public Task Init(Func <MessageContext, Task> onMessage, Func <ErrorContext, Task <ErrorHandleResult> > onError, CriticalError criticalError, PushSettings settings) { circuitBreaker = new RepeatedFailuresOverTimeCircuitBreaker("AzureStorageQueue-MessagePump", TimeToWaitBeforeTriggering, ex => criticalError.Raise("Failed to receive message from Azure Storage Queue.", ex)); messageReceiver.PurgeOnStartup = settings.PurgeOnStartup; receiveStrategy = ReceiveStrategy.BuildReceiveStrategy(onMessage, onError, settings.RequiredTransactionMode, criticalError); return(messageReceiver.Init(settings.InputQueue, settings.ErrorQueue)); }