Call Interceptor Extension
Call Interceptor Extension
Call Interceptor Extension
Extension Description
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:
- User-defined filters are executed after built-in filters by default.
- The special value
defaultindicates the position where the default extension point is inserted. For example:filter="xxx,default,yyy"meansxxxis before the default filter, andyyyis after it. - The special symbol
-indicates exclusion. For example:filter="-foo1"excludes the default extension pointfoo1. For instance:filter="-default"excludes all default extension points. - When filters are configured for both provider and service, all filters are accumulated rather than overridden. For example:
<dubbo:provider filter="xxx,yyy"/>and<dubbo:service filter="aaa,bbb" />meansxxx,yyy,aaa,bbbwill all be effective. To override, configure:<dubbo:service filter="-xxx,-yyy,aaa,bbb" />
Extension Interface
org.apache.dubbo.rpc.Filter
Extension Configuration
<!-- 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"/>
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
Extension Example
Maven 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
Feedback
Was this page helpful?
Yes No
Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)
