1、编写模块 dubbo-filter,引入 dubbo jar 包
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.5</version>
</dependency>
</dependencies>
2、编写 filter 类,按照规范
@Activate(group = {CommonConstants.CONSUMER,CommonConstants.PROVIDER})
public class DubboInvokerFilter implements Filter {
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
long start = System.currentTimeMillis();
try {
return invoker.invoke(invocation);
}finally {
System.out.println("invoke time:" + (System.currentTimeMillis() - start) + "毫秒");
}
}
}
3、在配置文件中注册过滤器
在指定文件夹下创建指定文件名称的文件
包名:META-INF/dubbo
文件名:org.apache.dubbo.rpc.Filter
timerFilter=com.lagou.filter.DubboInvokerFilter
4、在 demo-base 中引入该过滤器模块,进行测试
本文介绍了如何创建一个Dubbo过滤器模块,引入dubbo依赖,定义了一个@Activate的DubboInvokerFilter类,用于记录调用时间。然后在配置文件META-INF/dubbo下的org.apache.dubbo.rpc.Filter中注册该过滤器,并在其他项目中引入模块进行测试。
1448

被折叠的 条评论
为什么被折叠?



