The interception during the call process of service providers and consumers is mainly implemented based on this extension point. This interceptor is executed each time a remote method is invoked, so be mindful of its impact on performance.
Convention:
default indicates the position where the default extension point is inserted. For example: filter="xxx,default,yyy" means xxx is before the default filter, and yyy is after it.- indicates exclusion. For example: filter="-foo1" excludes the default extension point foo1. For instance: filter="-default" excludes all default extension points.<dubbo:provider filter="xxx,yyy"/> and <dubbo:service filter="aaa,bbb" /> means xxx, yyy, aaa, bbb will all be effective. To override, configure: <dubbo:service filter="-xxx,-yyy,aaa,bbb" />org.apache.dubbo.rpc.Filter
<!-- Consumer call process interception -->
<dubbo:reference filter="xxx,yyy" />
<!-- Default interceptor for consumer call process, which intercepts all references -->
<dubbo:consumer filter="xxx,yyy"/>
<!-- Provider call process interception -->
<dubbo:service filter="xxx,yyy" />
<!-- Default interceptor for provider call process, which intercepts all services -->
<dubbo:provider filter="xxx,yyy"/>
org.apache.dubbo.rpc.filter.EchoFilterorg.apache.dubbo.rpc.filter.GenericFilterorg.apache.dubbo.rpc.filter.GenericImplFilterorg.apache.dubbo.rpc.filter.TokenFilterorg.apache.dubbo.rpc.filter.AccessLogFilterorg.apache.dubbo.rpc.filter.CountFilterorg.apache.dubbo.rpc.filter.ActiveLimitFilterorg.apache.dubbo.rpc.filter.ClassLoaderFilterorg.apache.dubbo.rpc.filter.ContextFilterorg.apache.dubbo.rpc.filter.ConsumerContextFilterorg.apache.dubbo.rpc.filter.ExceptionFilterorg.apache.dubbo.rpc.filter.ExecuteLimitFilterorg.apache.dubbo.rpc.filter.DeprecatedFilterMaven project structure:
src
|-main
|-java
|-com
|-xxx
|-XxxFilter.java (implements Filter interface)
|-resources
|-META-INF
|-dubbo
|-org.apache.dubbo.rpc.Filter (plain text file, content: xxx=com.xxx.XxxFilter)
XxxFilter.java:
package com.xxx;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcException;
public class XxxFilter implements Filter {
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
// before filter ...
Result result = invoker.invoke(invocation);
// after filter ...
return result;
}
}
META-INF/dubbo/org.apache.dubbo.rpc.Filter:
xxx=com.xxx.XxxFilter