public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { using (_serviceProvider.CreateScope()) { await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { IMessageAttachment attachment = null; var queueName = AutoMessageMapper.GetQueueName <T>(); try { string attachmentId = null; if (typeof(ICommandWithAttachment).IsAssignableFrom(typeof(T))) { attachmentId = AttachmentUtility.GetAttachmentIds(messageStateHandler.MessageProperties).FirstOrDefault(); if (!string.IsNullOrEmpty(attachmentId)) { attachment = await _attachmentProvider.GetAttachmentAsync(queueName, attachmentId, cancellationToken).ConfigureAwait(false); var message = (ICommandWithAttachment)await messageStateHandler.GetMessageAsync().ConfigureAwait(false); message.Attachment = attachment; } } await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); if (attachment != null) { attachment.Stream?.Dispose(); await _attachmentProvider.DeleteAttachmentAsync(queueName, attachmentId, cancellationToken).ConfigureAwait(false); } } finally { attachment?.Stream?.Dispose(); } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { using (var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken)) { if (messageStateHandler is IMessageLockHandler <T> lockHandler && pipelineInformation.ProcessingSettings is IExtendMessageLockTimeout extendLock) { var token = cts.Token; #pragma warning disable 4014 Task.Run(async() => { await RenewLock(extendLock.ExtensionInterval, extendLock.ExtensionDuration, token, lockHandler, pipelineInformation.HostConfiguration.Log).ConfigureAwait(false); }, cancellationToken).ConfigureAwait(false); #pragma warning restore 4014 } try { await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } finally { //Stop the lock renewal cts.Cancel(); } } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { var messageName = typeof(T).FullName; using (var operation = _client.StartOperation <RequestTelemetry>(messageName)) { try { await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); // Add the message properties to the telemetry log foreach (var property in messageStateHandler.MessageProperties) { operation.Telemetry.Properties[property.Key] = property.Value; } operation.Telemetry.Success = true; } catch (Exception e) { operation.Telemetry.Success = false; _client.TrackException(e); throw; } } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { if (messageStateHandler.DeliveryCount > messageStateHandler.DeadLetterDeliveryLimit) { var processor = pipelineInformation.HostConfiguration.DependencyInjection.GetInstance <IProcessMessage <T> >(pipelineInformation.ProcessorInterfaceType); if (processor is IProcessBeforeDeadLetter <T> deadletterProcessor) { var message = await messageStateHandler.GetMessageAsync().ConfigureAwait(false); try { await deadletterProcessor.BeforeDeadLetterAsync(message, cancellationToken).ConfigureAwait(false); } catch (Exception e) { pipelineInformation.HostConfiguration.Log.Error(e, "Failed before deadletter processing {@" + typeof(T).Name + "}", message); } } await messageStateHandler.DeadLetterAsync(messageStateHandler.DeadLetterDeliveryLimit).ConfigureAwait(false); return; } await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { using (AsyncScopedLifestyle.BeginScope(_container)) { await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { using (var scope = messageStateHandler.MessageScope.GetScope()) { messageStateHandler.MessageScope = scope; await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { if (messageStateHandler.DeliveryCount > messageStateHandler.DeadLetterDeliveryLimit) { await messageStateHandler.DeadLetterAsync(messageStateHandler.DeadLetterDeliveryLimit).ConfigureAwait(false); return; } await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, CancellationToken cancellationToken) where T : class, IMessage { var typedMessage = await messageStateHandler.GetMessageAsync().ConfigureAwait(false); var messageHandler = _processorProvider.GetProcessor <T>(typeof(TMessageProcessor)); await messageHandler.ProcessAsync(typedMessage, cancellationToken) .ContinueWith(task => messageStateHandler.CompleteAsync(), TaskContinuationOptions.OnlyOnRanToCompletion) .ConfigureAwait(false); }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, CancellationToken cancellationToken) where T : class, IMessage { var typedMessage = await messageStateHandler.GetMessageAsync().ConfigureAwait(false); var messageHandler = _processorProvider.GetInstance <IProcessMessage <T> >(typeof(TMessageProcessor)); await messageHandler.ProcessAsync(typedMessage, cancellationToken).ConfigureAwait(false); await messageStateHandler.CompleteAsync().ConfigureAwait(false); }
public async Task ProcessAsync<T>(IMessageStateHandler<T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { //Is this a saga var processor = messageStateHandler.MessageScope.GetInstance<IProcessMessage<T>>(pipelineInformation.ProcessorInterfaceType); if (processor is ISaga saga) { var sagaType = ReflectionHelper.GetAllInterfacesImplementingOpenGenericInterface(processor.GetType(), typeof(ISaga<>)).Single(); var sagaDataType = sagaType.GenericTypeArguments[0]; var sagaHandlerType = typeof(SagaHandler<,>).MakeGenericType(sagaDataType, typeof(T)); var message = await messageStateHandler.GetMessageAsync().ConfigureAwait(false); var sagaHandler = (ISagaHandler)Activator.CreateInstance(sagaHandlerType, _sagaStore, processor, message); try { await sagaHandler.Initialize().ConfigureAwait(false); } catch (SagaAlreadyStartedException e) { // If the processor is ISagaDuplicateDetected, let the processor process the duplicate message before completing the saga if (processor is ISagaDuplicateDetected<T> sagaDetectedHandler) { await sagaDetectedHandler.ProcessDuplicateAsync(message, cancellationToken).ConfigureAwait(false); } else { pipelineInformation.HostConfiguration.Log.Information(e, "Saga already started"); } await messageStateHandler.CompleteAsync().ConfigureAwait(false); return; } try { await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } catch (Exception) { if (saga.MessageMapper.IsStartMessage(typeof(T))) { //If we have started a saga but the start message fails then we must make sure the message can be retried await _sagaStore.Complete(saga.PartitionKey, saga.Id).ConfigureAwait(false); } throw; } } else { await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { try { await _semaphoreQueue.WaitAsync().ConfigureAwait(false); await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } finally { _semaphoreQueue.Release(); } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { if (!_stopwatch.IsRunning) { _stopwatch.Start(); } await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); if (++_count % 1000 == 0) { Console.WriteLine($"Processed {_count} messages in {_stopwatch.Elapsed} {_count / _stopwatch.Elapsed.TotalSeconds} m/s"); } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { var queueName = AutoMessageMapper.GetQueueName <T>(); var log = pipelineInformation?.HostConfiguration?.Log; log?.Debug("{ThreadCount} remaining threads that can process messages in {QueueName} in {Name}", _semaphoreQueue.CurrentCount, queueName, nameof(ThrottlingMiddleware)); await _semaphoreQueue.WaitAsync(cancellationToken).ConfigureAwait(false); try { await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } finally { _semaphoreQueue.Release(); } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { var messageName = typeof(T).FullName; NewRelic.Api.Agent.NewRelic.SetTransactionName("Message", messageName); var transaction = _agent.CurrentTransaction; try { await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); // Add the message properties to the telemetry log foreach (var property in messageStateHandler.MessageProperties) { transaction.AddCustomAttribute(property.Key, property.Value); } } catch (Exception e) { NewRelic.Api.Agent.NewRelic.NoticeError(e); throw; } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { T message = null; try { message = await messageStateHandler.GetMessageAsync().ConfigureAwait(false); await next.ProcessAsync(messageStateHandler, cancellationToken).ConfigureAwait(false); } catch (Exception e) { _log.Error(e, "Error processing message {@" + typeof(T).Name + "}", message); try { await messageStateHandler.AbandonByErrorAsync(e).ConfigureAwait(false); } catch (Exception exception) { _log.Error(exception, "Failed to abandon message {@" + typeof(T).Name + "}", message); } } }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IPipelineInformation pipelineInformation, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { _list.Add(_order); await next.ProcessAsync(messageStateHandler, cancellationToken); }
public Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, CancellationToken cancellationToken) where T : class, IMessage { return(_current.ProcessAsync(messageStateHandler, _next, cancellationToken)); }
public async Task ProcessAsync <T>(IMessageStateHandler <T> messageStateHandler, IMessageProcessor next, CancellationToken cancellationToken) where T : class, IMessage { await next.ProcessAsync(messageStateHandler, cancellationToken).ContinueWith(task => _list.Add(_order), cancellationToken); }