Exemple #1
0
        protected async Task SendRequest(BehaviorContext <TInstance> context, ConsumeContext consumeContext, TRequest requestMessage)
        {
            var pipe = new SendRequestPipe(consumeContext.ReceiveContext.InputAddress);

            var endpoint = await consumeContext.GetSendEndpoint(_request.Settings.ServiceAddress).ConfigureAwait(false);

            await endpoint.Send(requestMessage, pipe).ConfigureAwait(false);

            _request.SetRequestId(context.Instance, pipe.RequestId);

            if (_request.Settings.Timeout > TimeSpan.Zero)
            {
                var now            = DateTime.UtcNow;
                var expirationTime = now + _request.Settings.Timeout;

                RequestTimeoutExpired message = new TimeoutExpired(now, expirationTime, context.Instance.CorrelationId, pipe.RequestId);

                MessageSchedulerContext schedulerContext;
                if (_request.Settings.SchedulingServiceAddress != null)
                {
                    var scheduleEndpoint = await consumeContext.GetSendEndpoint(_request.Settings.SchedulingServiceAddress).ConfigureAwait(false);

                    await scheduleEndpoint.ScheduleSend(consumeContext.ReceiveContext.InputAddress, expirationTime, message).ConfigureAwait(false);
                }
                else if (consumeContext.TryGetPayload(out schedulerContext))
                {
                    await schedulerContext.ScheduleSend(expirationTime, message).ConfigureAwait(false);
                }
                else
                {
                    throw new ConfigurationException("A request timeout was specified but no message scheduler was specified or available");
                }
            }
        }
        protected async Task SendRequest(BehaviorContext <TInstance> context, ConsumeContext consumeContext, TRequest requestMessage, Uri serviceAddress)
        {
            Guid requestId = _request.GenerateRequestId(context.Instance);

            var pipe = new SendRequestPipe(_request, consumeContext.ReceiveContext.InputAddress, requestId);

            var endpoint = serviceAddress == null
                ? new ConsumeSendEndpoint(await consumeContext.ReceiveContext.PublishEndpointProvider.GetPublishSendEndpoint <TRequest>().ConfigureAwait
                                              (false), consumeContext, default)
Exemple #3
0
        /// <summary>
        /// Sends an individual request to the specified service address and records the results.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="consumeContext"></param>
        /// <param name="requestMessage"></param>
        /// <param name="serviceAddress"></param>
        /// <returns></returns>
        protected async Task SendRequest(BehaviorContext <TInstance> context, ConsumeContext consumeContext, TRequest requestMessage, Uri serviceAddress)
        {
            var pipe = new SendRequestPipe(consumeContext.ReceiveContext.InputAddress);

            if (serviceAddress != null)
            {
                // specific service address specfied, send
                var endpoint = await consumeContext.GetSendEndpoint(serviceAddress).ConfigureAwait(false);

                await endpoint.Send(requestMessage, pipe).ConfigureAwait(false);
            }
            else
            {
                // no service address specified, publish
                await consumeContext.Publish(requestMessage, pipe).ConfigureAwait(false);
            }

            // add new state item
            request.Accessor.Insert(context, requestMessage, pipe.RequestId);

            // if a timeout is specified, schedule the timeout expired message
            if (request.Settings.Timeout > TimeSpan.Zero)
            {
                var now            = DateTime.UtcNow;
                var expirationTime = now + request.Settings.Timeout;

                var message = new TimeoutExpired <TRequest>(now, expirationTime, context.Instance.CorrelationId, pipe.RequestId);

                if (consumeContext.TryGetPayload <MessageSchedulerContext>(out var schedulerContext))
                {
                    await schedulerContext.ScheduleSend(expirationTime, message).ConfigureAwait(false);
                }
                else
                {
                    throw new ConfigurationException("A request timeout was specified but no message scheduler was specified or available.");
                }
            }
        }