public MediatorClientFactoryContext(ISendEndpoint endpoint, IConsumePipe connector, Uri responseAddress, RequestTimeout defaultTimeout = default)
        {
            _endpoint  = endpoint;
            _connector = connector;

            ResponseAddress = responseAddress;
            DefaultTimeout  = defaultTimeout.Or(RequestTimeout.Default);
        }
        public ReceiveEndpointClientFactoryContext(ReceiveEndpointReady receiveEndpointReady, RequestTimeout defaultTimeout = default)
        {
            _receiveEndpoint = receiveEndpointReady.ReceiveEndpoint;

            ResponseAddress = receiveEndpointReady.InputAddress;
            DefaultTimeout  = defaultTimeout.Or(RequestTimeout.Default);

            _publishEndpoint = new Lazy <IPublishEndpoint>(CreatePublishEndpoint);
        }
Esempio n. 3
0
        public RequestHandle <TRequest> Create(object values, CancellationToken cancellationToken = default, RequestTimeout timeout = default)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            async Task <TRequest> Request(Guid requestId, IPipe <SendContext <TRequest> > pipe, CancellationToken token)
            {
                return(await _requestSendEndpoint.Send(requestId, values, pipe, token).ConfigureAwait(false));
            }

            return(new ClientRequestHandle <TRequest>(_context, Request, cancellationToken, timeout.Or(_timeout)));
        }
Esempio n. 4
0
        public RequestHandle <TRequest> Create(TRequest message, CancellationToken cancellationToken, RequestTimeout timeout)
        {
            async Task <TRequest> Request(Guid requestId, IPipe <SendContext <TRequest> > pipe, CancellationToken token)
            {
                await _requestSendEndpoint.Send(requestId, message, pipe, token).ConfigureAwait(false);

                return(message);
            }

            return(new ClientRequestHandle <TRequest>(_context, Request, cancellationToken, timeout.Or(_timeout)));
        }
Esempio n. 5
0
        async Task <Response <T1, T2, T3> > GetResponseInternal <T1, T2, T3>(ClientRequestHandle <TRequest> .SendRequestCallback request, CancellationToken
                                                                             cancellationToken, RequestTimeout timeout, RequestPipeConfiguratorCallback <TRequest> callback = null)
            where T1 : class
            where T2 : class
            where T3 : class
        {
            using RequestHandle <TRequest> handle = new ClientRequestHandle <TRequest>(_context, request, cancellationToken, timeout.Or(_timeout));

            callback?.Invoke(handle);

            Task <Response <T1> > result1 = handle.GetResponse <T1>(false);
            Task <Response <T2> > result2 = handle.GetResponse <T2>(false);
            Task <Response <T3> > result3 = handle.GetResponse <T3>();

            var task = await Task.WhenAny(result1, result2, result3).ConfigureAwait(false);

            await task.ConfigureAwait(false);

            return(new Response <T1, T2, T3>(result1, result2, result3));
        }
Esempio n. 6
0
        async Task <Response <T> > GetResponseInternal <T>(ClientRequestHandle <TRequest> .SendRequestCallback request,
                                                           CancellationToken cancellationToken, RequestTimeout timeout, RequestPipeConfiguratorCallback <TRequest> callback = null)
            where T : class
        {
            using RequestHandle <TRequest> handle = new ClientRequestHandle <TRequest>(_context, request, cancellationToken, timeout.Or(_timeout));

            callback?.Invoke(handle);

            return(await handle.GetResponse <T>().ConfigureAwait(false));
        }
Esempio n. 7
0
        public IRequestClient <T> CreateRequestClient <T>(ConsumeContext consumeContext, RequestTimeout timeout)
            where T : class
        {
            if (EndpointConvention.TryGetDestinationAddress <T>(out var destinationAddress))
            {
                return(CreateRequestClient <T>(consumeContext, destinationAddress, timeout));
            }

            return(new RequestClient <T>(_context, _context.GetRequestEndpoint <T>(consumeContext), timeout.Or(_context.DefaultTimeout)));
        }
Esempio n. 8
0
 public IRequestClient <T> CreateRequestClient <T>(ConsumeContext consumeContext, Uri destinationAddress, RequestTimeout timeout)
     where T : class
 {
     return(new RequestClient <T>(_context, _context.GetRequestEndpoint <T>(destinationAddress, consumeContext), timeout.Or(_context.DefaultTimeout)));
 }
Esempio n. 9
0
 public async Task <Response <T> > GetResponse <T>(TRequest message, CancellationToken cancellationToken, RequestTimeout timeout)
     where T : class
 {
     using (RequestHandle <TRequest> handle = new ClientRequestHandle <TRequest>(_context, _requestSendEndpoint, message, cancellationToken,
                                                                                 timeout.Or(_timeout)))
     {
         return(await handle.GetResponse <T>().ConfigureAwait(false));
     }
 }
Esempio n. 10
0
 public RequestHandle <TRequest> Create(TRequest message, CancellationToken cancellationToken, RequestTimeout timeout)
 {
     return(new ClientRequestHandle <TRequest>(_context, _requestSendEndpoint, message, cancellationToken, timeout.Or(_timeout)));
 }
Esempio n. 11
0
        public RequestHandle <TRequest> Create(object values, CancellationToken cancellationToken = default, RequestTimeout timeout = default)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            Task <TRequest> request = _requestSendEndpoint.CreateMessage(values, cancellationToken);

            return(new ClientRequestHandle <TRequest>(_context, _requestSendEndpoint, request, cancellationToken, timeout.Or(_timeout)));
        }
Esempio n. 12
0
        public IRequestClient <T> CreateRequestClient <T>(RequestTimeout timeout)
            where T : class
        {
            if (EndpointConvention.TryGetDestinationAddress <T>(out var destinationAddress))
            {
                return(CreateRequestClient <T>(destinationAddress, timeout));
            }

            return(new RequestClient <T>(_context, new PublishRequestSendEndpoint <T>(_context.PublishEndpoint), timeout.Or(_context.DefaultTimeout)));
        }
Esempio n. 13
0
        public RequestHandle <TRequest> Create(object values, CancellationToken cancellationToken = default, RequestTimeout timeout = default)
        {
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }

            Task <InitializeContext <TRequest> > request = _requestSendEndpoint.CreateMessage(values, cancellationToken);

            async Task <TRequest> Message()
            {
                var message = await request.ConfigureAwait(false);

                return(message.Message);
            }

            return(new ClientRequestHandle <TRequest>(_context, _requestSendEndpoint, Message(), cancellationToken, timeout.Or(_timeout)));
        }
Esempio n. 14
0
        async Task <Response <T1, T2> > GetResponseInternal <T1, T2>(ClientRequestHandle <TRequest> .SendRequestCallback request, CancellationToken cancellationToken,
                                                                     RequestTimeout timeout)
            where T1 : class
            where T2 : class
        {
            using RequestHandle <TRequest> handle = new ClientRequestHandle <TRequest>(_context, request, cancellationToken, timeout.Or(_timeout));

            Task <Response <T1> > result1 = handle.GetResponse <T1>(false);
            Task <Response <T2> > result2 = handle.GetResponse <T2>();

            await Task.WhenAny(result1, result2).ConfigureAwait(false);

            return(new Response <T1, T2>(result1, result2));
        }