首页  

dubbo 自定义 filter 实例     所属分类 dubbo 浏览量 222
Filter
ProtocolFilterWrapper Filter链

原生的Filter

ConsumerContextFilter  Consumer上下文传递

自定义filter

@Activate(group = {Constants.PROVIDER, Constants.CONSUMER})
public class DubboHelloFilter implements Filter

META-INF/dubbo/com.alibaba.dubbo.rpc.Filter
hello=dyyx.DubboHelloFilter



import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcException;

@Activate(group = {Constants.PROVIDER, Constants.CONSUMER})
public class DubboHelloFilter implements Filter{
    
    public DubboHelloFilter() {
        System.out.println("DubboHelloFilter() run "+LocalDateTime.now()+"\n\n\n");
    }

    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        long start = System.currentTimeMillis();
        Result result = invoker.invoke(invocation);
        long end = System.currentTimeMillis();
        long time = end - start;
        System.out.println("DubboHelloFilter time="+time+"\n\n\n");
        return result;
    }

}


完整代码
https://gitee.com/dyyx/dubbodemo/blob/master/dubbo-hello-filter/src/main/java/dyyx/DubboHelloFilter.java


dubbo RpcContexta attachments 实例 Dubbo Filter 顺序 dubbo 分布式追踪 traceId 传递要点

上一篇     下一篇
dubbo之RpcContext

dubbo RpcContexta attachments 实例

Dubbo Filter 顺序

TBA聊考研

springboot REST api 实例

基于 HttpURLConnection 的 http 客户端