Dubbo拦截器实现的原理,我的理解就是实现或扩展Dubbo自己的Filter接口(LogFilter implements Filter),然后将这个类在配置文件(META-INF/dubbo/com.alibaba.dubbo.rpc.Filter文本文件)中与一个名称对应(logFilter),然后在dubbo配置文件中对需要增加拦截器的bean进行配置。
我在之前自己搭建的消费者当中实现了一个filter
1.Consumer端增加LogFilter类,扩展Filter
package com.mohrss.service;
import com.alibaba.dubbo.rpc.*;
public class LogFilter implements Filter {
public Result invoke(Invoker> invoker, Invocation invocation) throws RpcException {
// TODO Auto-generated method stub
Result result = null;
Long takeTime = 0L;
try{
Long startTime = System.currentTimeMillis();
//before filter
System.out.println("before filter");
result = invoker.invoke(invocation);
if (result.getException() instanceof Exception)
{
throw new Exception(result.ge