public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context,
     AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     AddConnectionName(context);
     return(continuation(context));
 }
Exemplo n.º 2
0
 AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context,
                                                AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     context = AddMetadata(context);
     LogCall(context.Method);
     return(base.AsyncDuplexStreamingCall(context, continuation));
 }
Exemplo n.º 3
0
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context,
     AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     throw new RpcException(new Status(StatusCode.Unimplemented,
                                       "secure streaming calls are not supported"));
 }
Exemplo n.º 4
0
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     LogCall(context.Method);
     AddCallerMetadata(ref context);
     return(continuation(context));
 }
Exemplo n.º 5
0
 public override AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>
 (
     ClientInterceptorContext<TRequest, TResponse> context,
     AsyncDuplexStreamingCallContinuation<TRequest, TResponse> continuation
 )
 {
     return base.AsyncDuplexStreamingCall(context, continuation);
 }
Exemplo n.º 6
0
        /// <summary>
        /// 拦截异步双向流调用
        /// </summary>
        /// <param name="context"></param>
        /// <param name="continuation"></param>
        /// <typeparam name="TRequest"></typeparam>
        /// <typeparam name="TResponse"></typeparam>
        /// <returns></returns>
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var clientId = context.Options.Headers?.GetClientId() ?? "";

            CheckRepeat(clientId, ServiceProvider.GetJsonProvider().Serializer(context), context.GetGenericTypeName());
            return(continuation(context));
        }
Exemplo n.º 7
0
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            LogCall(context.Method);

            var call = continuation(context);

            return(new AsyncDuplexStreamingCall <TRequest, TResponse>(call.RequestStream, call.ResponseStream, call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose));
        }
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var response = continuation(context);

            return(new AsyncDuplexStreamingCall <TRequest, TResponse>(response.RequestStream,
                                                                      new StreamReader <TResponse>(response.ResponseStream, ReportNewLeader), response.ResponseHeadersAsync,
                                                                      response.GetStatus, response.GetTrailers, response.Dispose));
        }
Exemplo n.º 9
0
 /// <summary>
 /// AsyncDuplexStreamingCall
 /// </summary>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <param name="context"></param>
 /// <param name="continuation"></param>
 /// <returns></returns>
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context
     , AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(Call(context
                 , () =>
     {
         return continuation(context);
     }) as AsyncDuplexStreamingCall <TRequest, TResponse>);
 }
Exemplo n.º 10
0
        private AsyncDuplexStreamingCallContinuation <TRequest, TResponse> getAsyncDuplexStreamingCallChain <TRequest, TResponse>(Interceptor interceptor, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
            where TRequest : class
            where TResponse : class
        {
            AsyncDuplexStreamingCallContinuation <TRequest, TResponse> fun = (fContext) =>
            {
                return(interceptor.AsyncDuplexStreamingCall(fContext, continuation));
            };

            return(fun);
        }
        /// <summary>
        /// Makes an asynchronous connection for a read and write stream via gRPC and logs any errors that occur.
        /// </summary>
        /// <param name="context">The gRPC context (service, method, etc.).</param>
        /// <param name="continuation">The actual client method implementation function.</param>
        /// <returns>A wrapped asynchronous call.</returns>
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = base.AsyncDuplexStreamingCall(context, continuation);

            var fields = FieldsFromContext(context);
            var logger = _logger.WithFields(fields);

            return(WrapCall(call, logger, context.Options.CancellationToken));
        }
Exemplo n.º 12
0
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var callContext = new ClientCallInterceptorContext(context.Options, context.Host, context.Method);

            var call = base.AsyncDuplexStreamingCall(context, continuation);

            return(new AsyncDuplexStreamingCall <TRequest, TResponse>(
                       new ClientStreamWriterInterceptor <TRequest>(call.RequestStream, callContext, CallInterceptor),
                       new AsyncStreamReaderInterceptor <TResponse>(call.ResponseStream, callContext, CallInterceptor),
                       call.ResponseHeadersAsync,
                       call.GetStatus,
                       call.GetTrailers,
                       call.Dispose));
        }
Exemplo n.º 13
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <param name="context"></param>
 /// <param name="continuation"></param>
 /// <returns></returns>
 /// <exception cref="AppException"></exception>
 /// <exception cref="UnauthorizedAccessException"></exception>
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context,
     AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     try
     {
         return(continuation(context));
     }
     catch (RpcException rpc)
     {
         HandleException(rpc);
     }
     catch (AggregateException ag)
     {
         HandleException(ag);
     }
     // never reached
     return(null);
 }
        /// <inheritdoc/>
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            ClientRpcScope <TRequest, TResponse> rpcScope = null;

            try
            {
                rpcScope = new ClientRpcScope <TRequest, TResponse>(context, this.options);
                var responseContinuation = continuation(rpcScope.Context);

                var requestStreamProxy = new ClientStreamWriterProxy <TRequest>(
                    responseContinuation.RequestStream,
                    rpcScope.RecordRequest,
                    onException: rpcScope.CompleteWithException);

                var responseStreamProxy = new AsyncStreamReaderProxy <TResponse>(
                    responseContinuation.ResponseStream,
                    rpcScope.RecordResponse,
                    rpcScope.Complete,
                    rpcScope.CompleteWithException);

                return(new AsyncDuplexStreamingCall <TRequest, TResponse>(
                           requestStreamProxy,
                           responseStreamProxy,
                           responseContinuation.ResponseHeadersAsync,
                           responseContinuation.GetStatus,
                           responseContinuation.GetTrailers,
                           responseContinuation.WithBestEffortDispose(rpcScope)));
            }
            catch (Exception e)
            {
                rpcScope?.CompleteWithException(e);
                throw;
            }
            finally
            {
                rpcScope?.RestoreParentActivity();
            }
        }
Exemplo n.º 15
0
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     Console.WriteLine("AsyncDuplexStreamingCall 异步双向流拦截");
     return(base.AsyncDuplexStreamingCall(context, continuation));
 }
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     SaveExecutionContextTo(EnsureHeaders(ref context));
     return(base.AsyncDuplexStreamingCall(context, continuation));
 }
Exemplo n.º 17
0
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(new InterceptedClientHandler <TRequest, TResponse>(_tracer, context)
            .AsyncDuplexStreamingCall(continuation));
 }
Exemplo n.º 18
0
        /// <summary>
        /// Intercepts an asynchronous invocation of a duplex streaming remote call.
        /// </summary>
        /// <typeparam name="TRequest">The type of the request.</typeparam>
        /// <typeparam name="TResponse">The type of the response.</typeparam>
        /// <param name="context">The context associated with the invocation.</param>
        /// <param name="continuation">A delegate that asynchronously proceeds with the invocation, calling the next  interceptor in the chain, or the service request handler, in case of the last interceptor and the interceptor can choose to call it zero or more times at its discretion. The interceptor has the ability to wrap or substitute the request value and the response stream when calling the continuation.</param>
        /// <returns>A return object of the invocation.</returns>
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = base.AsyncDuplexStreamingCall(context, continuation);

            if (!DeepIntercepterEnabled)
            {
                return(call);
            }

            IClientStreamWriter <TRequest> streamWriter = CreateClientStreamWriter(call.RequestStream, context);
            IAsyncStreamReader <TResponse> streamReader = CreateClientStreamReader(call.ResponseStream, context);
            Task <Metadata> getHeader  = InterceptGetResponseHeaders(call.ResponseHeadersAsync, context);
            Func <Status>   getStatus  = () => { return(InterceptGetStatus(call.GetStatus, context)); };
            Func <Metadata> getTrailer = () => { return(InterceptGetTrailers(call.GetTrailers, context)); };

            return(new AsyncDuplexStreamingCall <TRequest, TResponse>(streamWriter, streamReader, getHeader, getStatus, getTrailer, call.Dispose));
        }
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = continuation(ConfigureContext(context, out var cts));

            if (cts == null)
            {
                return(call);
            }
            else
            {
                return(new AsyncDuplexStreamingCall <TRequest, TResponse>(
                           requestStream: call.RequestStream,
                           responseStream: call.ResponseStream,
                           responseHeadersAsync: DuplexStreamingCallbacks <TRequest, TResponse> .GetResponseHeadersAsync,
                           getStatusFunc: DuplexStreamingCallbacks <TRequest, TResponse> .GetStatus,
                           getTrailersFunc: DuplexStreamingCallbacks <TRequest, TResponse> .GetTrailers,
                           disposeAction: DuplexStreamingCallbacks <TRequest, TResponse> .Dispose,
                           CreateContextState(call, cts)));
            }
        }
Exemplo n.º 20
0
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = continuation(ConfigureContext(context, out var cts));

            if (cts == null)
            {
                return(call);
            }
            else
            {
                return(new AsyncDuplexStreamingCall <TRequest, TResponse>(
                           call.RequestStream,
                           call.ResponseStream,
                           call.ResponseHeadersAsync,
                           call.GetStatus,
                           call.GetTrailers,
                           () => { call.Dispose(); cts.Dispose(); }));
            }
        }
Exemplo n.º 21
0
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var info    = context.Method.FullName.Split('/');
            var service = info[1];
            var method  = info[2];

            OngoingRequests.Labels(service, method).Inc();

            using (RequestResponseHistogram.Labels(service, method).NewTimer())
            {
                try
                {
                    return(continuation(context));
                }
                catch (RpcException e)
                {
                    TotalErrors.Labels(service, method, e.StatusCode.ToString()).Inc();
                    throw;
                }
                finally
                {
                    OngoingRequests.Labels(service, method).Dec();
                }
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// Intercepts an asynchronous invocation of a duplex streaming call.
 /// </summary>
 /// <param name="context">
 /// The <see cref="Grpc.Core.Interceptors.ClientInterceptorContext{TRequest, TResponse}"/>
 /// associated with the current invocation.
 /// </param>
 /// <param name="continuation">
 /// The callback that continues the invocation process.
 /// This can be invoked zero or more times by the interceptor.
 /// The interceptor can invoke the continuation passing the given
 /// context argument, or substitute as it sees fit.
 /// </param>
 /// <returns>
 /// An instance of <see cref="Grpc.Core.AsyncDuplexStreamingCall{TRequest, TResponse}" />
 /// representing an asynchronous duplex-streaming invocation.
 /// The interceptor can simply return the return value of the
 /// continuation delegate passed to it intact, or construct its
 /// own substitute as it sees fit.
 /// </returns>
 public virtual AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
     where TRequest : class
     where TResponse : class
 {
     return(continuation(context));
 }
Exemplo n.º 23
0
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = continuation(context);

            var streamWrapper = new AsyncStreamReaderWrapper <TResponse>(call.ResponseStream);

            return(new AsyncDuplexStreamingCall <TRequest, TResponse>(call.RequestStream, streamWrapper, _ => call.ResponseHeadersAsync,
                                                                      _ => call.GetStatus(), _ => call.GetTrailers(), _ => call.Dispose(), null));
        }
Exemplo n.º 24
0
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(continuation(GetNewContext(context)));
 }
Exemplo n.º 25
0
        public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var innerContinuation = continuation;

            foreach (var filterItem in _filterList)
            {
                innerContinuation = getAsyncDuplexStreamingCallChain(filterItem, innerContinuation);
            }

            return(base.AsyncDuplexStreamingCall(context, innerContinuation));
        }
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     _callback(context.Options);
     return(continuation(context));
 }
 public override AsyncDuplexStreamingCall <TRequest, TResponse> AsyncDuplexStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context,
                                                                                                               AsyncDuplexStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     // Authorize any method if the user is logged in.
     addJwtHeaders(ref context);
     return(base.AsyncDuplexStreamingCall(context, continuation));
 }