【问题标题】:Await for continuation method in grpc interceptor in c#在c#中等待grpc拦截器中的延续方法
【发布时间】:2019-01-15 12:21:33
【问题描述】:

我想在 c# .net 核心中有一个用于 grpc 的拦截器,以检查所有请求凭据并记录所有 rpc 异常,但如果在没有 Await 关键字的情况下调用 Continuation 方法,则其异常不会在此级别引发。所以我等待拦截器继续捕获所有异常。 到目前为止一切正常,但我不知道它是否会在以后特别是在多个 cincurrent rpc 调用中引起任何问题?

    public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request, ServerCallContext context, UnaryServerMethod<TRequest, TResponse> continuation)
    {
        try
        {
            CheckLogin(context);
            var res = await continuation(request, context);        
            return res;
        }
        catch (RpcException ex)
        {
            _logger.LogError(ex, "RPC Error. UnaryServerHanler Error. Method : {method}", context.Method);
            throw ex;
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "UnaryServerHanler Error. Method : {method}", context.Method);
            throw ex;
        }
    }

【问题讨论】:

    标签: c# rpc grpc


    【解决方案1】:

    您不必担心在执行异步方法时使用 await 关键字。

    实际上,这种机制是为了更好地处理并发代码执行而构建的。

    请关注https://stackoverflow.com/a/14178317/7779827

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-15
      • 1970-01-01
      • 2021-05-11
      • 2019-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多