コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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");
                }
            }
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: PublishActivity.cs プロジェクト: zz110/MassTransit
        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);
        }
コード例 #7
0
        async Task Execute(BehaviorContext <TInstance> context)
        {
            var consumeContext = context.CreateConsumeContext();

            TRequest requestMessage = _messageFactory(consumeContext);

            await SendRequest(context, consumeContext, requestMessage).ConfigureAwait(false);
        }
コード例 #8
0
        async Task Execute(BehaviorContext <TInstance> context)
        {
            var consumeContext = context.CreateConsumeContext();

            TMessage message = _messageFactory(consumeContext);

            await consumeContext.Publish(message, _publishPipe);
        }
コード例 #9
0
        Task Execute(BehaviorContext <TInstance> context)
        {
            ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext();

            var message = _messageFactory(consumeContext);

            return(consumeContext.Publish(message, _publishPipe));
        }
コード例 #10
0
ファイル: RequestActivity.cs プロジェクト: zzms/MassTransit
        Task Execute(BehaviorContext <TInstance> context)
        {
            ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext();

            var requestMessage = _messageFactory(consumeContext);

            return(SendRequest(context, consumeContext, requestMessage, _serviceAddressProvider(consumeContext)));
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: RequestActivity.cs プロジェクト: zagyar/MassTransit
        Task Execute(BehaviorContext <TInstance> context)
        {
            var consumeContext = context.CreateConsumeContext();

            TRequest requestMessage = _messageFactory(consumeContext);

            return(SendRequest(context, consumeContext, requestMessage));
        }
コード例 #13
0
        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);
            }
        }
コード例 #14
0
ファイル: RespondActivity.cs プロジェクト: lsfera/MassTransit
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        /// <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;
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
ファイル: SendActivity.cs プロジェクト: zz110/MassTransit
        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);
            }
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        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);
                }
            }
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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);
        }