public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context,
     AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     AddConnectionName(context);
     return(continuation(context));
 }
예제 #2
0
 AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context,
                                                AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     context = AddMetadata(context);
     LogCall(context.Method);
     return(base.AsyncClientStreamingCall(context, continuation));
 }
예제 #3
0
 public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context,
     AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     throw new RpcException(new Status(StatusCode.Unimplemented,
                                       "secure streaming calls are not supported"));
 }
예제 #4
0
 public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     LogCall(context.Method);
     AddCallerMetadata(ref context);
     return(continuation(context));
 }
예제 #5
0
        AsyncClientStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            Console.WriteLine($"AsyncClientStreamingCall: {context.Method.FullName}");

            return(base.AsyncClientStreamingCall(context, continuation));
        }
예제 #6
0
 public override AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>
 (
     ClientInterceptorContext<TRequest, TResponse> context,
     AsyncClientStreamingCallContinuation<TRequest, TResponse> continuation
 )
 {
     return base.AsyncClientStreamingCall(context, continuation);
 }
예제 #7
0
        /// <summary>
        /// 拦截异步客户端流调用
        /// </summary>
        /// <param name="context"></param>
        /// <param name="continuation"></param>
        /// <typeparam name="TRequest"></typeparam>
        /// <typeparam name="TResponse"></typeparam>
        /// <returns></returns>
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var clientId = context.Options.Headers?.GetClientId() ?? "";

            CheckRepeat(clientId, ServiceProvider.GetJsonProvider().Serializer(context), context.GetGenericTypeName());
            return(continuation(context));
        }
예제 #8
0
 /// <summary>
 /// AsyncClientStreamingCall
 /// </summary>
 /// <typeparam name="TRequest"></typeparam>
 /// <typeparam name="TResponse"></typeparam>
 /// <param name="context"></param>
 /// <param name="continuation"></param>
 /// <returns></returns>
 public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
     ClientInterceptorContext <TRequest, TResponse> context
     , AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(Call(context
                 , () =>
     {
         return continuation(context);
     }) as AsyncClientStreamingCall <TRequest, TResponse>);
 }
예제 #9
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            LogCall(context.Method);

            var call = continuation(context);

            return(new AsyncClientStreamingCall <TRequest, TResponse>(call.RequestStream, call.ResponseAsync, call.ResponseHeadersAsync, call.GetStatus, call.GetTrailers, call.Dispose));
        }
예제 #10
0
        private AsyncClientStreamingCallContinuation <TRequest, TResponse> getAsyncClientStreamingCallChain <TRequest, TResponse>(Interceptor interceptor, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
            where TRequest : class
            where TResponse : class
        {
            AsyncClientStreamingCallContinuation <TRequest, TResponse> fun = (fContext) =>
            {
                return(interceptor.AsyncClientStreamingCall(fContext, continuation));
            };

            return(fun);
        }
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var response = continuation(context);

            response.ResponseAsync.ContinueWith(ReportNewLeader, ContinuationOptions);

            return(new AsyncClientStreamingCall <TRequest, TResponse>(response.RequestStream, response.ResponseAsync,
                                                                      response.ResponseHeadersAsync, response.GetStatus, response.GetTrailers, response.Dispose));
        }
        /// <inheritdoc/>
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            ClientRpcScope <TRequest, TResponse> rpcScope = null;

            try
            {
                rpcScope = new ClientRpcScope <TRequest, TResponse>(context, this.options);
                var responseContinuation     = continuation(rpcScope.Context);
                var clientRequestStreamProxy = new ClientStreamWriterProxy <TRequest>(
                    responseContinuation.RequestStream,
                    rpcScope.RecordRequest,
                    onException: rpcScope.CompleteWithException);

                var responseAsync = responseContinuation.ResponseAsync.ContinueWith(
                    responseTask =>
                {
                    try
                    {
                        var response = responseTask.Result;
                        rpcScope.RecordResponse(response);
                        rpcScope.Complete();
                        return(response);
                    }
                    catch (AggregateException ex)
                    {
                        rpcScope.CompleteWithException(ex.InnerException);
                        throw ex.InnerException;
                    }
                });

                return(new AsyncClientStreamingCall <TRequest, TResponse>(
                           clientRequestStreamProxy,
                           responseAsync,
                           responseContinuation.ResponseHeadersAsync,
                           responseContinuation.GetStatus,
                           responseContinuation.GetTrailers,
                           responseContinuation.WithBestEffortDispose(rpcScope)));
            }
            catch (Exception e)
            {
                rpcScope?.CompleteWithException(e);
                throw;
            }
            finally
            {
                rpcScope?.RestoreParentActivity();
            }
        }
예제 #13
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var callContext = new ClientCallInterceptorContext(context.Options, context.Host, context.Method);

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

            return(new AsyncClientStreamingCall <TRequest, TResponse>(
                       new ClientStreamWriterInterceptor <TRequest>(call.RequestStream, callContext, CallInterceptor),
                       WaitAsyncUnaryCall(callContext, call.ResponseAsync),
                       call.ResponseHeadersAsync,
                       call.GetStatus,
                       call.GetTrailers,
                       call.Dispose));
        }
예제 #14
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(
            ClientInterceptorContext <TRequest, TResponse> context,
            AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var response = continuation(context);

            return(new AsyncClientStreamingCall <TRequest, TResponse>(
                       response.RequestStream,
                       response.ResponseAsync.ContinueWith(t => {
                if (t.Exception?.InnerException is RpcException ex)
                {
                    throw ConvertRpcException(ex);
                }

                return t.Result;
            }),
                       response.ResponseHeadersAsync,
                       response.GetStatus,
                       response.GetTrailers,
                       response.Dispose));
        }
예제 #15
0
 public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(continuation(GetNewContext(context)));
 }
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var span = BuildClientSpan <TRequest, TResponse>(context);
            var res  = base.AsyncClientStreamingCall(context, continuation);

            //TODO: How to close here? continue is right?

            res.ResponseHeadersAsync.ContinueWith((r) => {
                if (r.IsCanceled)
                {
                    span.Log("canceled");
                }
                else
                if (r.IsFaulted)
                {
                    span.Log("faulted"); //add r.Excpetion? //must use error as event log see https://github.com/opentracing/specification/blob/master/semantic_conventions.md#log-fields-table
                }
                else
                {
                    span.Log(new Dictionary <string, object> {
                        { "completed", res.GetStatus().StatusCode }
                    });
                }
                span.Finish();
            });

            return(res);
        }
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = continuation(ConfigureContext(context, out var cts));

            if (cts == null)
            {
                return(call);
            }
            else
            {
                return(new AsyncClientStreamingCall <TRequest, TResponse>(
                           requestStream: call.RequestStream,
                           responseAsync: call.ResponseAsync,
                           responseHeadersAsync: ClientStreamingCallbacks <TRequest, TResponse> .GetResponseHeadersAsync,
                           getStatusFunc: ClientStreamingCallbacks <TRequest, TResponse> .GetStatus,
                           getTrailersFunc: ClientStreamingCallbacks <TRequest, TResponse> .GetTrailers,
                           disposeAction: ClientStreamingCallbacks <TRequest, TResponse> .Dispose,
                           CreateContextState(call, cts)));
            }
        }
예제 #18
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = continuation(ConfigureContext(context, out var cts));

            if (cts == null)
            {
                return(call);
            }
            else
            {
                return(new AsyncClientStreamingCall <TRequest, TResponse>(
                           call.RequestStream,
                           call.ResponseAsync,
                           call.ResponseHeadersAsync,
                           call.GetStatus,
                           call.GetTrailers,
                           () => { call.Dispose(); cts.Dispose(); }));
            }
        }
예제 #19
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <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();
                }
            }
        }
예제 #20
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var innerContinuation = continuation;

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

            return(base.AsyncClientStreamingCall(context, innerContinuation));
        }
예제 #21
0
 /// <summary>
 /// Intercepts an asynchronous invocation of a client 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.AsyncClientStreamingCall{TRequest, TResponse}" />
 /// representing an asynchronous client-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 AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
     where TRequest : class
     where TResponse : class
 {
     return(continuation(context));
 }
예제 #22
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var responseCnt   = continuation(context);
            var responseAsync = responseCnt.ResponseAsync.ContinueWith(responseTask =>
            {
                try
                {
                    return(responseTask.Result);
                }
                catch (Exception caugth)
                {
                    var(converted, ok) = ExceptionConverter.Convert(caugth);
                    if (!ok)
                    {
                        throw;
                    }
                    throw converted;
                }
            });


            return(new AsyncClientStreamingCall <TRequest, TResponse>(responseCnt.RequestStream, responseAsync, responseCnt.ResponseHeadersAsync, responseCnt.GetStatus, responseCnt.GetTrailers, responseCnt.Dispose));
        }
 public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     SaveExecutionContextTo(EnsureHeaders(ref context));
     return(base.AsyncClientStreamingCall(context, continuation));
 }
예제 #24
0
 public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     Console.WriteLine("AsyncClientStreamingCall 异步客户端流调用拦截");
     return(base.AsyncClientStreamingCall(context, continuation));
 }
 public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     _callback(context.Options);
     return(continuation(context));
 }
예제 #26
0
        /// <summary>
        /// Intercepts an asynchronous invocation of a client 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 AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = base.AsyncClientStreamingCall(context, continuation);

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

            IClientStreamWriter <TRequest> streamWriter = CreateClientStreamWriter(call.RequestStream, context);
            Task <TResponse> getResponse = InterceptGetResponse(call.ResponseAsync, 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 AsyncClientStreamingCall <TRequest, TResponse>(streamWriter, getResponse, getHeader, getStatus, getTrailer, call.Dispose));
        }
예제 #27
0
 public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
 {
     return(new InterceptedClientHandler <TRequest, TResponse>(_tracer, context)
            .AsyncClientStreamingCall(continuation));
 }
예제 #28
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            var call = continuation(context);

            var responseTask = Handle(call);

            return(new AsyncClientStreamingCall <TRequest, TResponse>(call.RequestStream, responseTask, _ => call.ResponseHeadersAsync,
                                                                      _ => call.GetStatus(), _ => call.GetTrailers(), _ => call.Dispose(), null));
        }
예제 #29
0
            public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
            {
                var response      = continuation(context);
                int counter       = 0;
                var requestStream = new WrappedClientStreamWriter <TRequest>(response.RequestStream,
                                                                             message => { counter++; return(message); }, null);
                var responseAsync = response.ResponseAsync.ContinueWith(
                    unaryResponse => (TResponse)(object)counter.ToString()  // Cast to object first is needed to satisfy the type-checker
                    );

                return(new AsyncClientStreamingCall <TRequest, TResponse>(requestStream, responseAsync, response.ResponseHeadersAsync, response.GetStatus, response.GetTrailers, response.Dispose));
            }
예제 #30
0
        public override AsyncClientStreamingCall <TRequest, TResponse> AsyncClientStreamingCall <TRequest, TResponse>(ClientInterceptorContext <TRequest, TResponse> context, AsyncClientStreamingCallContinuation <TRequest, TResponse> continuation)
        {
            AddBearerTokenCallerMetadata(ref context);

            return(continuation(context));
        }