Call Intercept Extension
Expansion Description
Service provider and service consumer call process interception. Most functions of Dubbo itself are implemented based on this extension point. Every time a remote method is executed, this interception will be executed. Please pay attention to the impact on performance.
agreement:
- User-defined filters are by default after built-in filters.
- The special value
default, indicating where the default extension point is inserted. For example:filter="xxx,default,yyy", meansxxxis before the default filter, andyyyis after the default filter. - The special symbol
-means culling. For example:filter="-foo1", exclude adding the default extension pointfoo1. For example:filter="-default", remove all default extension points. - When the provider and service configure filters at the same time, all filters are accumulated instead of overwritten. For example:
<dubbo:provider filter="xxx,yyy"/>and<dubbo:service filter="aaa,bbb" />, thenxxx,yyy,aaa,bbbwill take effect. If you want to overwrite, you need to configure:<dubbo:service filter="-xxx,-yyy,aaa,bbb" />
Extension ports
org.apache.dubbo.rpc.Filter
Extended configuration
<!-- Consumer call process interception -->
<dubbo:reference filter="xxx,yyy" />
<!-- The default interceptor of the consumer call process, which will intercept all references -->
<dubbo:consumer filter="xxx,yyy"/>
<!-- provider call process interception -->
<dubbo:service filter="xxx,yyy" />
<!-- Provider call process default interceptor, will intercept all services -->
<dubbo:provider filter="xxx,yyy"/>
Known extensions
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.DeprecatedFilter
Extended example
Maven project structure:
src
|-main
|-java
|-com
|-xxx
|-XxxFilter.java (implement the 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
Last modified January 2, 2023: Enhance en docs (#1798) (95a9f4f6c1)
