public override async Task InvokeAsync(IPipeContext context, CancellationToken token) { var machine = context.GetStateMachine(); await _stateMachineActivator.PersistAsync(machine); await Next.InvokeAsync(context, token); }
public async Task Iterate(IPipeContext context) { foreach (var iteration in iterationPipeline) { await iteration.Process(context); } }
public override async Task InvokeAsync(IPipeContext context, CancellationToken token = default(CancellationToken)) { if (!ShouldExecute(context)) { await Next.InvokeAsync(context, token); return; } var properties = GetBasicProperties(context); var headerKey = GetHeaderKey(context); if (properties.Headers.ContainsKey(headerKey)) { await Next.InvokeAsync(context, token); return; } var item = GetHeaderItem(context) ?? CreateHeaderItem(context); var serializedItem = SerializeItem(item, context); properties.Headers.TryAdd(headerKey, serializedItem); await Next.InvokeAsync(context, token); }
public override async Task InvokeAsync(IPipeContext context, CancellationToken token) { var callback = GetCallback(context); if (callback == null) { _logger.Debug("No Mandatory Callback registered."); await Next.InvokeAsync(context, token); return; } var channel = GetChannel(context); if (channel == null) { _logger.Warn("Channel not found in Pipe Context. Mandatory Callback not registered."); await Next.InvokeAsync(context, token); return; } _logger.Debug("Register Mandatory Callback on channel {channelNumber}", channel.ChannelNumber); channel.BasicReturn += callback; PostInvoke?.Invoke(context, callback); await Next.InvokeAsync(context, token); _logger.Debug("Removing Mandatory Callback on channel {channelNumber}", channel.ChannelNumber); channel.BasicReturn -= callback; }
public override Task InvokeAsync(IPipeContext context, CancellationToken token = default(CancellationToken)) { var queueDeclaration = GetQueueDeclaration(context); SaveToContext(context, queueDeclaration); return(Next.InvokeAsync(context, token)); }
public override Task InvokeAsync(IPipeContext context, CancellationToken token) { var requestType = _requestTypeFunc(context); var responseType = _responseTypeFunc(context); var action = context.Get <Action <IRespondConfigurationBuilder> >(PipeKey.ConfigurationAction); if (requestType == null) { throw new ArgumentNullException(nameof(requestType)); } if (responseType == null) { throw new ArgumentNullException(nameof(responseType)); } var defaultCfg = _factory.Create(requestType, responseType); var builder = new RespondConfigurationBuilder(defaultCfg); action?.Invoke(builder); var respondCfg = builder.Config; context.Properties.TryAdd(PipeKey.ConsumerConfiguration, respondCfg); context.Properties.TryAdd(PipeKey.ConsumeConfiguration, respondCfg.Consume); context.Properties.TryAdd(PipeKey.QueueDeclaration, respondCfg.Queue); context.Properties.TryAdd(PipeKey.ExchangeDeclaration, respondCfg.Exchange); return(Next.InvokeAsync(context, token)); }
public override Task InvokeAsync(IPipeContext context, CancellationToken token) { var requestType = context.GetRequestMessageType(); var responseType = context.GetResponseMessageType(); if (requestType == null) { throw new ArgumentNullException(nameof(requestType)); } if (responseType == null) { throw new ArgumentNullException(nameof(responseType)); } var defaultCfg = _factory.Create(requestType, responseType); var builder = new RequestConfigurationBuilder(defaultCfg); var action = context.Get <Action <IRequestConfigurationBuilder> >(PipeKey.ConfigurationAction); action?.Invoke(builder); var requestConfig = builder.Config; context.Properties.TryAdd(RequestKey.Configuration, requestConfig); context.Properties.TryAdd(PipeKey.PublisherConfiguration, requestConfig.Request); context.Properties.TryAdd(PipeKey.ConsumerConfiguration, requestConfig.Response); context.Properties.TryAdd(PipeKey.ConsumeConfiguration, requestConfig.Response.Consume); return(Next.InvokeAsync(context, token)); }
protected virtual void UpdateRoutingKey(IPipeContext context, string executionId) { _logger.Debug("Updating routing key with GlobalExecutionId {globalExecutionId}", executionId); var updated = UpdateAction(context, executionId); _logger.Info("Routing key updated with GlobalExecutionId: {globalExecutionId}", updated); }
public override Task InvokeAsync(IPipeContext context, CancellationToken token) { var config = ExtractConfigFromMessageType(context) ?? ExtractConfigFromStrings(context); if (config == null) { Logger.LogWarning("Unable to find PublisherConfiguration from message type or parameters."); throw new ArgumentNullException(nameof(config)); } var action = context.Get <Action <IPublisherConfigurationBuilder> >(PipeKey.ConfigurationAction); if (action != null) { Logger.LogDebug($"Custom configuration supplied. Applying."); var builder = new PublisherConfigurationBuilder(config); action(builder); config = builder.Config; } context.Properties.TryAdd(PipeKey.PublisherConfiguration, config); context.Properties.TryAdd(PipeKey.BasicPublishConfiguration, config); context.Properties.TryAdd(PipeKey.ExchangeDeclaration, config.Exchange); context.Properties.TryAdd(PipeKey.BasicProperties, config.BasicProperties); context.Properties.TryAdd(PipeKey.ReturnCallback, config.ReturnCallback); return(Next.InvokeAsync(context, token)); }
protected virtual PublisherConfiguration ExtractConfigFromStrings(IPipeContext context) { var routingKey = RoutingKeyFunc(context); var exchange = ExchangeFunc(context); return(PublisherFactory.Create(exchange, routingKey)); }
public override Task InvokeAsync(IPipeContext context, CancellationToken token = new CancellationToken()) { #if NETSTANDARD1_6 context.UseHttpContext(_httpAccessor.HttpContext); #endif return(Next.InvokeAsync(context, token)); }
public override async Task InvokeAsync(IPipeContext context, CancellationToken token = default(CancellationToken)) { var consumer = await GetOrCreateConsumerAsync(context, token); context.Properties.TryAdd(PipeKey.Consumer, consumer); await Next.InvokeAsync(context, token); }
public override async Task InvokeAsync(IPipeContext context, CancellationToken token = new CancellationToken()) { using (var scope = _serviceProvider.CreateScope()) { var messageProcessor = scope.ServiceProvider.GetRequiredService <IMessageProcessor>(); var messageId = context.GetDeliveryEventArgs().BasicProperties.MessageId; _logger.LogTrace($"Received a unique message with id: {messageId} to be processed."); if (!await messageProcessor.TryProcessAsync(messageId)) { _logger.LogTrace($"A unique message with id: {messageId} was already processed."); return; } try { _logger.LogTrace($"Processing a unique message with id: {messageId}..."); await Next.InvokeAsync(context, token); _logger.LogTrace($"Processed a unique message with id: {messageId}."); } catch { _logger.LogTrace($"There was an error when processing a unique message with id: {messageId}."); await messageProcessor.RemoveAsync(messageId); throw; } } }
public override async Task InvokeAsync(IPipeContext context, CancellationToken token) { var channel = GetOrCreateChannel(context); var exchangeName = GetExchangeName(context); var routingKey = GetRoutingKey(context); var mandatory = GetMandatoryOptions(context); var basicProps = GetBasicProps(context); var body = GetMessageBody(context); _logger.Info("Performing basic publish with routing key {routingKey} on exchange {exchangeName}.", routingKey, exchangeName); ExclusiveExecute(channel, c => BasicPublish( channel: c, exchange: exchangeName, routingKey: routingKey, mandatory: mandatory, basicProps: basicProps, body: body, context: context ), token ); await Next.InvokeAsync(context, token); }
protected virtual object GetMessage(IPipeContext context) { var bodyBytes = GetBodyBytes(context); var messageType = GetMessageType(context); return(Serializer.Deserialize(messageType, bodyBytes)); }
public override Task InvokeAsync(IPipeContext context, CancellationToken token = new CancellationToken()) { var globalExecutionId = GetGlobalExecutionId(context); PersistInProcess(globalExecutionId); return(Next.InvokeAsync(context, token)); }
protected override void BasicPublish( IModel channel, string exchange, string routingKey, bool mandatory, IBasicProperties basicProps, byte[] body, IPipeContext context) { var policy = context.GetPolicy(PolicyKeys.BasicPublish); var policyTask = policy.ExecuteAsync( action: () => { base.BasicPublish(channel, exchange, routingKey, mandatory, basicProps, body, context); return(Task.FromResult(true)); }, contextData: new Dictionary <string, object> { [RetryKey.PipeContext] = context, [RetryKey.ExchangeName] = exchange, [RetryKey.RoutingKey] = routingKey, [RetryKey.PublishMandatory] = mandatory, [RetryKey.BasicProperties] = basicProps, [RetryKey.PublishBody] = body, }); policyTask.ConfigureAwait(false); policyTask.GetAwaiter().GetResult(); }
public override async Task Process(IPipeContext context) { while (this.HasNextPipe) { await this.NextPipe.Process(context); } }
public override Task InvokeAsync(IPipeContext context, CancellationToken token) { var activated = GetActivatedFlag(context); if (!activated) { return(Next.InvokeAsync(context, token)); } var declaration = GetQueueDeclaration(context); if (declaration == null) { return(Next.InvokeAsync(context, token)); } var suffix = GetCustomQueueSuffix(context); if (SkipSuffix(suffix)) { return(Next.InvokeAsync(context, token)); } AppendSuffix(declaration, suffix); var consumeConfig = GetConsumeConfig(context); AlignConsumerConfig(consumeConfig, declaration); return(Next.InvokeAsync(context, token)); }
public override async Task InvokeAsync(IPipeContext context, CancellationToken token = default(CancellationToken)) { var channel = await GetChannelAsync(context, token); SaveInContext(context, channel); await Next.InvokeAsync(context, token); }
public override async Task Process(IPipeContext context) { var dataContext = context as GeoJsonContext; if (dataContext == null) { throw new NotSupportedException("The pipeline context must be of type DataPipelineContext"); } // Save time and space only read the first line to determine if this is a Feature or a // // Feature collection // string capture = ""; using (var reader = new StringReader(dataContext.OriginalData)) { bool finishedSearch = false; while (!finishedSearch) { var character = reader.ReadLine(); if (capture.IndexOf(',') < 0) { capture += character; } else { finishedSearch = true; } } if (capture.Contains("FeatureCollection")) { dataContext.Features = JsonConvert.DeserializeObject <GeoJSON.Net.Feature.FeatureCollection>(dataContext.OriginalData); } else if (capture.Contains("Feature")) { var feature = JsonConvert.DeserializeObject <GeoJSON.Net.Feature.Feature>(dataContext.OriginalData); dataContext.Features = new GeoJSON.Net.Feature.FeatureCollection(new List <GeoJSON.Net.Feature.Feature> { feature }); } else if (capture.Contains("MultiLineString")) { var multiline = JsonConvert.DeserializeObject <GeoJSON.Net.Geometry.MultiLineString>(dataContext.OriginalData); var feature = new GeoJSON.Net.Feature.Feature(multiline); dataContext.Features = new GeoJSON.Net.Feature.FeatureCollection(new List <GeoJSON.Net.Feature.Feature> { feature }); } else { throw new NotSupportedException("Type of GeoJson data could not be determined."); } } while (this.HasNextPipe) { await this.NextPipe.Process(context); } }
public override Task InvokeAsync(IPipeContext context, CancellationToken token = new CancellationToken()) { var props = GetBasicProps(context); var id = GetGlobalExecutionId(context); AddIdToHeader(props, id); return(Next.InvokeAsync(context, token)); }
protected virtual void SaveInContext(IPipeContext context, PublicationAddress replyTo) { if (ContextSaveAction == null) { _logger.Warn("No context save action found. Reply to address will not be saved."); } ContextSaveAction?.Invoke(context, replyTo); }
protected virtual PublisherConfiguration ExtractConfigFromMessageType(IPipeContext context) { var messageType = GetMessageType(context); return(messageType == null ? null : PublisherFactory.Create(messageType)); }
protected virtual Task <StateMachineBase> GetStateMachineAsync(IPipeContext context, Guid id, Type type) { var fromContext = StateMachineFunc?.Invoke(context); return(fromContext != null ? Task.FromResult(fromContext) : _stateMachineActivator.ActivateAsync(id, type)); }
protected virtual void AddAcknowledgementToContext(IPipeContext context, ConsumeConfiguration cfg) { if (cfg.AutoAck) { return; } context.Properties.TryAdd(PipeKey.MessageAcknowledgement, new Ack()); }
public override Task InvokeAsync(IPipeContext context, CancellationToken token) { var args = GetDeliveryArgs(context); var replyTo = GetReplyTo(args); SaveInContext(context, replyTo); return(Next.InvokeAsync(context, token)); }
protected virtual BasicPublishConfiguration GetInitialConfig(IPipeContext context) { var message = context.GetMessage(); return(message != null ? _factory.Create(message) : _factory.Create()); }
public override Task InvokeAsync(IPipeContext context, CancellationToken token) { var message = GetMessage(context); var serialized = SerializeMessage(message); AddSerializedMessageToContext(context, serialized); return(Next.InvokeAsync(context, token)); }
protected virtual void SaveInContext(IPipeContext context, object message) { if (PersistAction == null) { _logger.Warn("No persist action defined. Message will not be saved in Pipe context."); } PersistAction?.Invoke(context, message); }