async Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var message = _messageFactory?.Invoke(consumeContext) ?? await _asyncMessageFactory(consumeContext).ConfigureAwait(false); IPipe <SendContext <TMessage> > sendPipe = _contextCallback != null ? Pipe.Execute <SendContext <TMessage> >(sendContext => { _contextCallback(consumeContext, sendContext); }) : Pipe.Empty <SendContext <TMessage> >(); if (_destinationAddressProvider != null) { var destinationAddress = _destinationAddressProvider(consumeContext); var endpoint = await consumeContext.GetSendEndpoint(destinationAddress).ConfigureAwait(false); await endpoint.Send(message, sendPipe).ConfigureAwait(false); } else { await consumeContext.Send(message, sendPipe).ConfigureAwait(false); } }
public async Task Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next) { ConsumeEventContext <TInstance, TData> consumeContext = context.CreateConsumeContext(); var payload = context.Data as Fault; InitializeContext <RequestFaulted <TRequest> > initializeContext = await MessageInitializerCache <RequestFaulted <TRequest> > .Initialize(new { context.Instance.CorrelationId, PayloadType = TypeMetadataCache <Fault <TRequest> > .MessageTypeNames, Payload = new { payload.FaultId, payload.FaultedMessageId, payload.Timestamp, payload.Host, payload.Exceptions } }).ConfigureAwait(false); object message = initializeContext.Message; await consumeContext.Publish(message, typeof(RequestFaulted)).ConfigureAwait(false); await next.Execute(context).ConfigureAwait(false); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeContext consumeContext = context.CreateConsumeContext(); Guid?requestId = _request.GetRequestId(context.Instance); if (requestId.HasValue && _request.Settings.Timeout > TimeSpan.Zero) { MessageSchedulerContext schedulerContext; if (_request.Settings.SchedulingServiceAddress != null) { var scheduleEndpoint = await consumeContext.GetSendEndpoint(_request.Settings.SchedulingServiceAddress).ConfigureAwait(false); await scheduleEndpoint.CancelScheduledSend(requestId.Value).ConfigureAwait(false); } else if (consumeContext.TryGetPayload(out schedulerContext)) { await schedulerContext.CancelScheduledSend(consumeContext.ReceiveContext.InputAddress, requestId.Value).ConfigureAwait(false); } else { throw new ConfigurationException("A scheduler was not available to cancel the scheduled request timeout"); } } }
async Task Execute(BehaviorContext <TInstance> context) { Guid?previousTokenId = _schedule.GetTokenId(context.Instance); ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var schedulerContext = context.GetPayload <MessageSchedulerContext>(); var message = _messageFactory?.Invoke(consumeContext) ?? await _asyncMessageFactory(consumeContext).ConfigureAwait(false); var delay = _timeProvider(consumeContext); ScheduledMessage <TMessage> scheduledMessage = await schedulerContext.ScheduleSend(delay, message, _sendPipe).ConfigureAwait(false); _schedule?.SetTokenId(context.Instance, scheduledMessage.TokenId); if (previousTokenId.HasValue) { Guid?messageTokenId = consumeContext.GetSchedulingTokenId(); if (!messageTokenId.HasValue || previousTokenId.Value != messageTokenId.Value) { await schedulerContext.CancelScheduledSend(consumeContext.ReceiveContext.InputAddress, previousTokenId.Value).ConfigureAwait(false); } } }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); MessageSchedulerContext schedulerContext; if (!((ConsumeContext)consumeContext).TryGetPayload(out schedulerContext)) { throw new ContextException("The scheduler context could not be retrieved."); } var message = _messageFactory(consumeContext); var delay = _delayProvider(consumeContext); ScheduledMessage <TMessage> scheduledMessage = await schedulerContext.ScheduleSend(delay, message, _sendPipe).ConfigureAwait(false); Guid?previousTokenId = _schedule.GetTokenId(context.Instance); if (previousTokenId.HasValue) { await schedulerContext.CancelScheduledSend(previousTokenId.Value).ConfigureAwait(false); } _schedule?.SetTokenId(context.Instance, scheduledMessage.TokenId); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var message = _messageFactory?.Invoke(consumeContext) ?? await _asyncMessageFactory(consumeContext).ConfigureAwait(false); await consumeContext.Publish(message, _publishPipe).ConfigureAwait(false); }
async Task Execute(BehaviorContext <TInstance> context) { var consumeContext = context.CreateConsumeContext(); TRequest requestMessage = _messageFactory(consumeContext); await SendRequest(context, consumeContext, requestMessage).ConfigureAwait(false); }
async Task Execute(BehaviorContext <TInstance> context) { var consumeContext = context.CreateConsumeContext(); TMessage message = _messageFactory(consumeContext); await consumeContext.Publish(message, _publishPipe); }
Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var message = _messageFactory(consumeContext); return(consumeContext.Publish(message, _publishPipe)); }
Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var requestMessage = _messageFactory(consumeContext); return(SendRequest(context, consumeContext, requestMessage, _serviceAddressProvider(consumeContext))); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var requestMessage = _messageFactory?.Invoke(consumeContext) ?? await _asyncMessageFactory(consumeContext).ConfigureAwait(false); await SendRequest(context, consumeContext, requestMessage, _serviceAddressProvider(consumeContext)).ConfigureAwait(false); }
Task Execute(BehaviorContext <TInstance> context) { var consumeContext = context.CreateConsumeContext(); TRequest requestMessage = _messageFactory(consumeContext); return(SendRequest(context, consumeContext, requestMessage)); }
async Task Execute(BehaviorContext <TInstance> context) { if (request.IsFinished(context)) { // dispatch signal to ourselves var endpoint = await context.GetSendEndpoint(context.CreateConsumeContext().ReceiveContext.InputAddress); await endpoint.Send(new MultiRequestFinishedSignal(), s => s.CorrelationId = context.Instance.CorrelationId, context.CancellationToken); } }
async Task Activity <TInstance, TData> .Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next) { var consumeContext = context.CreateConsumeContext(); TMessage message = _messageFactory(consumeContext); await consumeContext.RespondAsync(message, _responsePipe); await next.Execute(context); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var message = await _asyncMessageFactory(consumeContext).ConfigureAwait(false); ITopicProducer <TMessage> producer = context.GetProducer <TMessage>(); await producer.Produce(message, _pipe).ConfigureAwait(false); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var message = _messageFactory(consumeContext); var endpoint = await consumeContext.GetSendEndpoint(_destinationAddress).ConfigureAwait(false); await endpoint.Send(message, _sendPipe).ConfigureAwait(false); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var message = await _asyncMessageFactory(consumeContext).ConfigureAwait(false); var producer = await context.GetProducer(consumeContext, _nameProvider(consumeContext)); await producer.Produce(message, _pipe).ConfigureAwait(false); }
async Task Activity <TInstance, TData> .Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next) { ConsumeEventContext <TInstance, TData> consumeContext = context.CreateConsumeContext(); var message = _messageFactory(consumeContext); await consumeContext.RespondAsync(message, _responsePipe).ConfigureAwait(false); await next.Execute(context).ConfigureAwait(false); }
/// <summary> /// Captures a <see cref="RequestToken{TRequest}"/> instance from the current context. /// </summary> /// <typeparam name="TInstance"></typeparam> /// <typeparam name="TRequest"></typeparam> /// <param name="context"></param> /// <returns></returns> public static void CaptureRequestToken <TInstance, TRequest>(this BehaviorContext <TInstance, TRequest> context, IRequestTokenSetter <TRequest> token) { var consumeContext = context.CreateConsumeContext(); token.Request = context.Data; token.MessageId = consumeContext.MessageId.Value; token.RequestId = consumeContext.RequestId.Value; token.ConversationId = consumeContext.ConversationId; token.CorrelationId = consumeContext.CorrelationId; token.FaultAddress = consumeContext.FaultAddress; token.ResponseAddress = consumeContext.ResponseAddress; }
public async Task Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next) { ConsumeEventContext <TInstance, TData> consumeContext = context.CreateConsumeContext(); InitializeContext <RequestCompleted <TData> > initializeContext = await MessageInitializerCache <RequestCompleted <TData> > .Initialize(new { context.Instance.CorrelationId, InVar.Timestamp, PayloadType = TypeMetadataCache <TData> .MessageTypeNames, Payload = context.Data }).ConfigureAwait(false); object message = initializeContext.Message; await consumeContext.Publish(message, typeof(RequestCompleted)).ConfigureAwait(false); await next.Execute(context).ConfigureAwait(false); }
public async Task Execute(BehaviorContext <FutureState, T> context, Behavior <FutureState, T> next) { ConsumeEventContext <FutureState, T> consumeContext = context.CreateConsumeContext(); // this will need to be done by a consumer at some point, to handle retry/fault handling var trackingNumber = context.Instance.CorrelationId; var builder = new RoutingSlipBuilder(trackingNumber); builder.AddSubscription(consumeContext.ReceiveContext.InputAddress, RoutingSlipEvents.Completed | RoutingSlipEvents.Faulted); await _planner.PlanItinerary(consumeContext.Data, builder).ConfigureAwait(false); var routingSlip = builder.Build(); await consumeContext.Execute(routingSlip).ConfigureAwait(false); }
Task Execute(BehaviorContext <TInstance> context) { var consumeContext = context.CreateConsumeContext(); var requestId = consumeContext.RequestId; if (requestId.HasValue && request.Settings.Timeout > TimeSpan.Zero) { if (consumeContext.TryGetPayload <MessageSchedulerContext>(out var schedulerContext)) { return(schedulerContext.CancelScheduledSend(consumeContext.ReceiveContext.InputAddress, requestId.Value)); } throw new ConfigurationException("A scheduler was not available to cancel the scheduled request timeout"); } return(Task.CompletedTask); }
public async Task Execute(BehaviorContext <RequestState, RequestFaulted> context, Behavior <RequestState, RequestFaulted> next) { ConsumeEventContext <RequestState, RequestFaulted> consumeContext = context.CreateConsumeContext(); if (!context.Instance.ExpirationTime.HasValue || context.Instance.ExpirationTime.Value > DateTime.UtcNow) { string body = GetResponseBody(consumeContext, context.Instance); IPipe <SendContext> pipe = new FaultedMessagePipe(context.GetPayload <ConsumeContext>(), context.Instance, body); var endpoint = await context.GetSendEndpoint(context.Instance.ResponseAddress).ConfigureAwait(false); var scheduled = new FaultedEvent(); await endpoint.Send(scheduled, pipe).ConfigureAwait(false); } await next.Execute(context).ConfigureAwait(false); }
public async Task Execute(BehaviorContext <FutureState, OrderFryShake> context, Behavior <FutureState, OrderFryShake> next) { ConsumeEventContext <FutureState, OrderFryShake> consumeContext = context.CreateConsumeContext(); var orderLineId = NewId.NextGuid(); await consumeContext.Publish <OrderFry>(new { OrderId = context.Instance.CorrelationId, OrderLineId = orderLineId, context.Data.Size, __RequestId = InVar.Id, __ResponseAddress = consumeContext.ReceiveContext.InputAddress }, context.CancellationToken); context.Instance.Pending.Add(orderLineId); await next.Execute(context); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext(); var message = _messageFactory?.Invoke(consumeContext) ?? await _asyncMessageFactory(consumeContext).ConfigureAwait(false); if (_destinationAddressProvider != null) { var destinationAddress = _destinationAddressProvider(consumeContext); var endpoint = await consumeContext.GetSendEndpoint(destinationAddress).ConfigureAwait(false); await endpoint.Send(message, _sendPipe).ConfigureAwait(false); } else { await consumeContext.Send(message, _sendPipe).ConfigureAwait(false); } }
public async Task Execute(BehaviorContext <FutureState, SubmitOrder> context, Behavior <FutureState, SubmitOrder> next) { if (context.Data.Fries != null) { ConsumeEventContext <FutureState, SubmitOrder> consumeContext = context.CreateConsumeContext(); await Task.WhenAll(context.Data.Fries.Select(fry => consumeContext.Publish <OrderFry>(new { context.Data.OrderId, OrderLineId = fry.FryId, fry.Size, __RequestId = InVar.Id, __ResponseAddress = consumeContext.ReceiveContext.InputAddress }, context.CancellationToken))); context.Instance.Pending.UnionWith(context.Data.Fries.Select(x => x.FryId)); } await next.Execute(context); }
async Task Execute(BehaviorContext <TInstance> context) { var consumeContext = context.CreateConsumeContext(); if (messageFactory != null) { foreach (var message in messageFactory(consumeContext)) { await SendRequest(context, consumeContext, message, serviceAddressProvider(consumeContext)).ConfigureAwait(false); } } if (asyncMessageFactory != null) { await foreach (var message in asyncMessageFactory(consumeContext)) { await SendRequest(context, consumeContext, message, serviceAddressProvider(consumeContext)).ConfigureAwait(false); } } }
public async Task Execute(BehaviorContext <FutureState, SubmitOrder> context, Behavior <FutureState, SubmitOrder> next) { Burger[] burgers = context.Data.Burgers; if (burgers != null) { ConsumeEventContext <FutureState, SubmitOrder> consumeContext = context.CreateConsumeContext(); await Task.WhenAll(burgers.Select(burger => consumeContext.Publish <OrderBurger>(new { context.Data.OrderId, OrderLineId = burger.BurgerId, Burger = burger, __RequestId = InVar.Id, __ResponseAddress = consumeContext.ReceiveContext.InputAddress }, context.CancellationToken))); context.Instance.Pending.UnionWith(burgers.Select(x => x.BurgerId)); } await next.Execute(context); }
public async Task Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next) { ConsumeEventContext <TInstance, TData> consumeContext = context.CreateConsumeContext(); var initializeContext = await MessageInitializerCache <RequestStarted <TData> > .Initialize(new { context.Instance.CorrelationId, consumeContext.RequestId, consumeContext.ResponseAddress, consumeContext.FaultAddress, consumeContext.ExpirationTime, PayloadType = TypeMetadataCache <TData> .MessageTypeNames, Payload = context.Data }).ConfigureAwait(false); object message = initializeContext.Message; await consumeContext.Publish(message, typeof(RequestStarted)).ConfigureAwait(false); await next.Execute(context).ConfigureAwait(false); }
public async Task Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next) { var consumeContext = context.CreateConsumeContext(); var requestToken = await requestTokenFactory?.Invoke(consumeContext); var exception = await exceptionFactory?.Invoke(consumeContext); var sendEndpoint = await consumeContext.GetSendEndpoint(requestToken.FaultAddress ?? requestToken.ResponseAddress); var fault = new FaultEvent <TRequest>(requestToken.Request, requestToken.MessageId, HostMetadataCache.Host, exception, new string[0]); await sendEndpoint.Send(fault, ctx => { ctx.CorrelationId = requestToken.CorrelationId; ctx.ConversationId = requestToken.ConversationId; ctx.RequestId = requestToken.RequestId; contextCallback?.Invoke(ctx); }); await next.Execute(context).ConfigureAwait(false); }