Exemple #1
0
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
     TRequest request, ClientInterceptorContext <TRequest, TResponse> context,
     AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     throw new RpcException(new Status(StatusCode.Unimplemented,
                                       "secure streaming calls are not supported"));
 }
 /// <summary>
 /// 拦截异步服务端流调用
 /// </summary>
 /// <param name="request"></param>
 /// <param name="context"></param>
 /// <param name="continuation"></param>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <returns></returns>
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
     TRequest request, ClientInterceptorContext <TRequest, TResponse> context,
     AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     LogCall(context.Method);
     return(continuation(request, context));
 }
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
     TRequest request,
     ClientInterceptorContext <TRequest, TResponse> context,
     AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     AddConnectionName(context);
     return(continuation(request, context));
 }
Exemple #4
0
        /// <summary>
        /// 拦截异步服务端流调用
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <param name="continuation"></param>
        /// <typeparam name="TRequest"></typeparam>
        /// <typeparam name="TResponse"></typeparam>
        /// <returns></returns>
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request, ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var clientId = context.Options.Headers?.GetClientId() ?? "";

            CheckRepeat(clientId, ServiceProvider.GetJsonProvider().Serializer(request), request.GetGenericTypeName());
            return(continuation(request, context));
        }
Exemple #5
0
        AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            Console.WriteLine($"AsyncServerStreamingCall: {context.Method.FullName}");

            return(base.AsyncServerStreamingCall(request, context, continuation));
        }
 public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>
 (
     TRequest request,
     ClientInterceptorContext<TRequest, TResponse> context,
     AsyncServerStreamingCallContinuation<TRequest, TResponse> continuation
 )
 {
     return base.AsyncServerStreamingCall(request, context, continuation);
 }
Exemple #7
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var response = continuation(request, context);

            return(new AsyncServerStreamingCall <TResponse>(new AsyncStreamReader <TResponse>(response.ResponseStream),
                                                            response.ResponseHeadersAsync, response.GetStatus, response.GetTrailers, response.Dispose));
        }
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            LogCall(context.Method);

            var call = continuation(request, context);

            return(new AsyncServerStreamingCall <TResponse>(call.ResponseStream, call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose));
        }
Exemple #9
0
        private AsyncServerStreamingCallContinuation <TRequest, TResponse> getAsyncServerStreamingCallChain <TRequest, TResponse>(Interceptor interceptor, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
            where TRequest : class
            where TResponse : class
        {
            AsyncServerStreamingCallContinuation <TRequest, TResponse> fun = (fRequest, fContext) =>
            {
                return(interceptor.AsyncServerStreamingCall(fRequest, fContext, continuation));
            };

            return(fun);
        }
 /// <summary>
 /// AsyncServerStreamingCall
 /// </summary>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <param name="request"></param>
 /// <param name="context"></param>
 /// <param name="continuation"></param>
 /// <returns></returns>
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
     TRequest request
     , ClientInterceptorContext <TRequest, TResponse> context
     , AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(Call(context
                 , () =>
     {
         return continuation(request, context);
     }
                 , request) as AsyncServerStreamingCall <TResponse>);
 }
        /// <summary>
        /// Makes an asynchronous request for a stream of values via gRPC and logs any errors that occur.
        /// </summary>
        /// <param name="request">The gRPC request message.</param>
        /// <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 AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = base.AsyncServerStreamingCall(request, context, continuation);

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

            return(WrapCall(call, logger));
        }
Exemple #12
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            LogCall(context.Method);

            if (request is HelloRequest)
            {
                var helloRequest = request as HelloRequest;
                Console.WriteLine(helloRequest.Name);
            }
            var responseContinuation = continuation(request, context);

            return(responseContinuation);
        }
Exemple #13
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var callContext = new ClientCallInterceptorContext(context.Options, context.Host, context.Method);

            var call = base.AsyncServerStreamingCall(request, context, continuation);

            return(new AsyncServerStreamingCall <TResponse>(
                       new AsyncStreamReaderInterceptor <TResponse>(call.ResponseStream, callContext, CallInterceptor),
                       call.ResponseHeadersAsync,
                       call.GetStatus,
                       call.GetTrailers,
                       call.Dispose));
        }
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <param name="request"></param>
 /// <param name="context"></param>
 /// <param name="continuation"></param>
 /// <returns></returns>
 /// <exception cref="AppException"></exception>
 /// <exception cref="UnauthorizedAccessException"></exception>
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
     TRequest request,
     ClientInterceptorContext <TRequest, TResponse> context,
     AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     try
     {
         return(continuation(request, context));
     }
     catch (RpcException rpc)
     {
         HandleException(rpc);
     }
     catch (AggregateException ag)
     {
         HandleException(ag);
     }
     // never reached
     return(null);
 }
Exemple #15
0
        /// <summary>
        /// Intercepts an asynchronous invocation of a streaming remote call.
        /// </summary>
        /// <typeparam name="TRequest"></typeparam>
        /// <typeparam name="TResponse"></typeparam>
        /// <param name="request">The request message of the invocation.</param>
        /// <param name="context">The <see cref="T:Grpc.Core.Interceptors.ClientInterceptorContext`2" />
        /// 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
        /// request value and context arguments, or substitute them as it sees fit.</param>
        /// <returns>
        /// An instance of <see cref="T:Grpc.Core.AsyncServerStreamingCall`1" />
        /// representing an asynchronous server-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 override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request, ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            AsyncServerStreamingCall <TResponse> call           = continuation(request, context);
            StreamingRpcInterceptor <TResponse>  responseStream = null;

            responseStream = new StreamingRpcInterceptor <TResponse>(call.ResponseStream,
                                                                     delegate(TResponse response, AggregateException rpcException)
            {
                loggingHandler.HandleAsyncServerStreamingLogging(request, response,
                                                                 context, rpcException, call);
            });

            return(new AsyncServerStreamingCall <TResponse>(
                       responseStream,
                       call.ResponseHeadersAsync,
                       call.GetStatus,
                       call.GetTrailers,
                       call.Dispose
                       ));
        }
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            LogCall(context.Method);


            if (request is HelloRequest)
            {
                var helloRequest = request as HelloRequest;
                // Console.WriteLine(helloRequest.Name);

                // If there is a activate request, start to mirror the request.
                if (MirrorRequestsQueue.mirrorRequest)
                {
                    MirrorRequestsQueue.queue.Enqueue(helloRequest);
                }
            }
            var responseContinuation = continuation(request, context);

            return(responseContinuation);
        }
Exemple #17
0
        /// <inheritdoc/>
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(
            TRequest request,
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            ClientRpcScope <TRequest, TResponse> rpcScope = null;

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

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

                return(new AsyncServerStreamingCall <TResponse>(
                           responseStreamProxy,
                           responseContinuation.ResponseHeadersAsync,
                           responseContinuation.GetStatus,
                           responseContinuation.GetTrailers,
                           responseContinuation.WithBestEffortDispose(rpcScope)));
            }
            catch (Exception e)
            {
                rpcScope?.CompleteWithException(e);
                throw;
            }
            finally
            {
                rpcScope?.RestoreParentActivity();
            }
        }
Exemple #18
0
        /// <summary>
        /// Intercepts an asynchronous invocation of a server streaming remote call.
        /// </summary>
        /// <typeparam name="TRequest">The type of the request.</typeparam>
        /// <typeparam name="TResponse">The type of the response.</typeparam>
        /// <param name="request">The request of the invocation.</param>
        /// <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 AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = base.AsyncServerStreamingCall(request, context, continuation);

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

            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 AsyncServerStreamingCall <TResponse>(streamReader, getHeader, getStatus, getTrailer, call.Dispose));
        }
Exemple #19
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var token = Blocker.Block(GetAccessToken());

            var headers = new Metadata();

            headers.Add("Authorization", token);

            var newContext = new ClientInterceptorContext <TRequest, TResponse>(context.Method, context.Host, context.Options.WithHeaders(headers));

            return(base.AsyncServerStreamingCall(request, newContext, continuation));
        }
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     SaveExecutionContextTo(EnsureHeaders(ref context));
     return(base.AsyncServerStreamingCall(request, context, continuation));
 }
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context,
                                                                                                     AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(new InterceptedClientHandler <TRequest, TResponse>(_tracer, context)
            .AsyncServerStreamingCall(request, continuation));
 }
Exemple #22
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            AddBearerTokenCallerMetadata(ref context);

            return(continuation(request, context));
        }
Exemple #23
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            AddAzdsHeadersToMetadata(ref context);

            return(base.AsyncServerStreamingCall(request, context, continuation));
        }
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = continuation(request, ConfigureContext(context, out var cts));

            if (cts == null)
            {
                return(call);
            }
            else
            {
                return(new AsyncServerStreamingCall <TResponse>(
                           responseStream: call.ResponseStream,
                           responseHeadersAsync: ServerStreamingCallbacks <TResponse> .GetResponseHeadersAsync,
                           getStatusFunc: ServerStreamingCallbacks <TResponse> .GetStatus,
                           getTrailersFunc: ServerStreamingCallbacks <TResponse> .GetTrailers,
                           disposeAction: ServerStreamingCallbacks <TResponse> .Dispose,
                           CreateContextState(call, cts)));
            }
        }
Exemple #25
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = continuation(request, ConfigureContext(context, out var cts));

            if (cts == null)
            {
                return(call);
            }
            else
            {
                return(new AsyncServerStreamingCall <TResponse>(
                           call.ResponseStream,
                           call.ResponseHeadersAsync,
                           call.GetStatus,
                           call.GetTrailers,
                           () => { call.Dispose(); cts.Dispose(); }));
            }
        }
Exemple #26
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <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(request, context));
                }
                catch (RpcException e)
                {
                    TotalErrors.Labels(service, method, e.StatusCode.ToString()).Inc();
                    throw;
                }
                finally
                {
                    OngoingRequests.Labels(service, method).Dec();
                }
            }
        }
Exemple #27
0
 /// <summary>
 /// Intercepts an asynchronous invocation of a streaming remote call.
 /// </summary>
 /// <param name="request">The request message of the invocation.</param>
 /// <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
 /// request value and context arguments, or substitute them as it sees fit.
 /// </param>
 /// <returns>
 /// An instance of <see cref="Grpc.Core.AsyncServerStreamingCall{TResponse}" />
 /// representing an asynchronous server-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 AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
     where TRequest : class
     where TResponse : class
 {
     return(continuation(request, context));
 }
Exemple #28
0
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(continuation(request, GetNewContext(context)));
 }
 public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     Console.WriteLine("AsyncServerStreamingCall 异步服务端流拦截");
     return(base.AsyncServerStreamingCall(request, context, continuation));
 }
Exemple #30
0
        public override AsyncServerStreamingCall <TResponse> AsyncServerStreamingCall <TRequest, TResponse>(TRequest request, ClientInterceptorContext <TRequest, TResponse> context, AsyncServerStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var innerContinuation = continuation;

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

            return(base.AsyncServerStreamingCall(request, context, innerContinuation));
        }