Dubbo源码分析(TimeoutFilter、ExceptionFilter、TokenFilter)

来源:互联网 发布:淘宝卖家版手机版 编辑:程序博客网 时间:2024/04/30 04:41

 

 上篇博客来分析了一下日志Filter,这篇来看一下以下几个Filter


 TimeOutFilter:如果执行timeout,则log记录下,不干涉服务的运行


 


 ExceptionFilter:对执行的异常进行分类统计

 具体代码就不贴了,就是用try...catch...来执行,得到result后,来分析result中的异常信息


 TokenFilter:随机token令牌,需要做一下配置

 


 TokenFilter只负责用来验证两者是否一直,否则报错

public class TokenFilter implements Filter {public Result invoke(Invoker<?> invoker, Invocation inv)throws RpcException {    String token = invoker.getUrl().getParameter(Constants.TOKEN_KEY);    if (ConfigUtils.isNotEmpty(token)) {        Class<?> serviceType = invoker.getInterface();        Map<String, String> attachments = inv.getAttachments();    String remoteToken = attachments == null ? null : attachments.get(Constants.TOKEN_KEY);    //用来验证两者是否一直    if (! token.equals(remoteToken)) {    throw new RpcException("Invalid token! Forbid invoke remote service " + serviceType + " method " + inv.getMethodName() + "() from consumer " + RpcContext.getContext().getRemoteHost() + " to provider "  + RpcContext.getContext().getLocalHost());    }    }return invoker.invoke(inv);}}


 

 

0 0
原创粉丝点击