当前位置: 首页 > news >正文

NetCore Grpc拦截

客户端拦截:

    public class ClientLoggerInterceptor : Interceptor{public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(TRequest request,ClientInterceptorContext<TRequest, TResponse> context,AsyncUnaryCallContinuation<TRequest, TResponse> continuation){var requestStr = request.ToString();var requestMethod = context.Method;var response = continuation(request, context);return response;}public override AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TRequest, TResponse>(TRequest request, ClientInterceptorContext<TRequest, TResponse> context, AsyncServerStreamingCallContinuation<TRequest, TResponse> continuation){var requestStr = request.ToString();var requestMethod = context.Method;var call = base.AsyncServerStreamingCall(request, context, continuation);return call;}}

客户端拦截器注册:

services.AddGrpcClient<T>(options =>
{options.InterceptorRegistrations.Add(new Grpc.Net.ClientFactory.InterceptorRegistration(InterceptorScope.Client, s => new ClientLoggerInterceptor()));
});

服务端:

public class ServerLoggerInterceptor: Interceptor
{public override Task<TResponse> UnaryServerHandler<TRequest, TResponse>(TRequest request,ServerCallContext context,UnaryServerMethod<TRequest, TResponse> continuation){var requestStr = request.ToString();var requestMethod = context.Method;var response = continuation(request, context);return response;}
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • java并发编程概述
  • Blender 中导出模型fbx
  • 如何利用python进行统计显著性检验
  • 浅谈React
  • SpringBoot项目架构实战之“网关zuul搭建“
  • 机器学习筑基篇,​Ubuntu 24.04 快速安装 PyCharm IDE 工具,无需激活!
  • 景联文科技打造高质量图文推理问答数据集,赋能大语言模型提升推理能力
  • Java内存划分详解:从基础到进阶
  • C++命名空间详细介绍
  • iOS多target时怎么对InfoPlist进行国际化
  • 流程图编辑框架LogicFlow-vue-ts和js
  • spark基于Spark的对招聘信息的分析与设计-计算机毕业设计源码50716
  • 好玩的珠玑妙算-加作弊带概率空间+日志存储240705mindMaster
  • C# IOC容器、依赖注入和控制反转
  • 统信UOS桌面操作系统上删除系统升级后GRUB中的回滚条目与备份
  • @angular/forms 源码解析之双向绑定
  • 「前端」从UglifyJSPlugin强制开启css压缩探究webpack插件运行机制
  • HTTP那些事
  • Java精华积累:初学者都应该搞懂的问题
  • java中的hashCode
  • Js基础知识(四) - js运行原理与机制
  • JS学习笔记——闭包
  • Median of Two Sorted Arrays
  • Mithril.js 入门介绍
  • MQ框架的比较
  • React+TypeScript入门
  • Vim 折腾记
  • 不发不行!Netty集成文字图片聊天室外加TCP/IP软硬件通信
  • 基于web的全景—— Pannellum小试
  • 开发基于以太坊智能合约的DApp
  • 前端性能优化——回流与重绘
  • 算法---两个栈实现一个队列
  • 为物联网而生:高性能时间序列数据库HiTSDB商业化首发!
  • mysql面试题分组并合并列
  • ​520就是要宠粉,你的心头书我买单
  • ​如何防止网络攻击?
  • #数学建模# 线性规划问题的Matlab求解
  • (¥1011)-(一千零一拾一元整)输出
  • (day 2)JavaScript学习笔记(基础之变量、常量和注释)
  • (ibm)Java 语言的 XPath API
  • (LeetCode C++)盛最多水的容器
  • (机器学习-深度学习快速入门)第三章机器学习-第二节:机器学习模型之线性回归
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (数位dp) 算法竞赛入门到进阶 书本题集
  • (未解决)macOS matplotlib 中文是方框
  • (转)全文检索技术学习(三)——Lucene支持中文分词
  • .NET 4 并行(多核)“.NET研究”编程系列之二 从Task开始
  • .NET WebClient 类下载部分文件会错误?可能是解压缩的锅
  • .NET连接数据库方式
  • @property括号内属性讲解
  • @RequestBody与@RequestParam:Spring MVC中的参数接收差异解析
  • @Slf4j idea标红Cannot resolve symbol ‘log‘
  • [AIGC] CompletableFuture的重要方法有哪些?
  • [Android]RecyclerView添加HeaderView出现宽度问题
  • [APIO2015]巴厘岛的雕塑