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);
                }
            }
        }
示例#2
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);
            }
        }
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        async Task Activity <TInstance, TData> .Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next)
        {
            ConsumeEventContext <TInstance, TData> consumeContext = context.CreateConsumeContext();

            var message = _messageFactory?.Invoke(consumeContext) ?? await _asyncMessageFactory(consumeContext).ConfigureAwait(false);

            await consumeContext.RespondAsync(message, _responsePipe).ConfigureAwait(false);

            await next.Execute(context).ConfigureAwait(false);
        }
示例#6
0
        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);
            }
        }
示例#7
0
        async Task Execute(BehaviorContext <TInstance> context)
        {
            ConsumeEventContext <TInstance> consumeContext = context.CreateConsumeContext();

            if (!consumeContext.TryGetPayload(out MessageSchedulerContext schedulerContext))
            {
                throw new ContextException("The scheduler context could not be retrieved.");
            }

            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);

            Guid?previousTokenId = _schedule.GetTokenId(context.Instance);

            if (previousTokenId.HasValue)
            {
                await schedulerContext.CancelScheduledSend(consumeContext.ReceiveContext.InputAddress, previousTokenId.Value).ConfigureAwait(false);
            }

            _schedule?.SetTokenId(context.Instance, scheduledMessage.TokenId);
        }