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 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.
  • The special symbol - indicates exclusion. For example: filter="-foo1" excludes the default extension point foo1. 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" /> means xxx, yyy, aaa, bbb will all be effective. To override, configure: <dubbo:service filter="-xxx,-yyy,aaa,bbb" />

Extension Interface

org.apache.dubbo.rpc.Filter

Extension Configuration

  1. <!-- Consumer call process interception -->
  2. <dubbo:reference filter="xxx,yyy" />
  3. <!-- Default interceptor for consumer call process, which intercepts all references -->
  4. <dubbo:consumer filter="xxx,yyy"/>
  5. <!-- Provider call process interception -->
  6. <dubbo:service filter="xxx,yyy" />
  7. <!-- Default interceptor for provider call process, which intercepts all services -->
  8. <dubbo:provider filter="xxx,yyy"/>

Known Extensions

  • org.apache.dubbo.rpc.filter.EchoFilter
  • org.apache.dubbo.rpc.filter.GenericFilter
  • org.apache.dubbo.rpc.filter.GenericImplFilter
  • org.apache.dubbo.rpc.filter.TokenFilter
  • org.apache.dubbo.rpc.filter.AccessLogFilter
  • org.apache.dubbo.rpc.filter.CountFilter
  • org.apache.dubbo.rpc.filter.ActiveLimitFilter
  • org.apache.dubbo.rpc.filter.ClassLoaderFilter
  • org.apache.dubbo.rpc.filter.ContextFilter
  • org.apache.dubbo.rpc.filter.ConsumerContextFilter
  • org.apache.dubbo.rpc.filter.ExceptionFilter
  • org.apache.dubbo.rpc.filter.ExecuteLimitFilter
  • org.apache.dubbo.rpc.filter.DeprecatedFilter

Extension Example

Maven project structure:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxFilter.java (implements Filter interface)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-org.apache.dubbo.rpc.Filter (plain text file, content: xxx=com.xxx.XxxFilter)

XxxFilter.java:

  1. package com.xxx;
  2. import org.apache.dubbo.rpc.Filter;
  3. import org.apache.dubbo.rpc.Invoker;
  4. import org.apache.dubbo.rpc.Invocation;
  5. import org.apache.dubbo.rpc.Result;
  6. import org.apache.dubbo.rpc.RpcException;
  7. public class XxxFilter implements Filter {
  8. public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
  9. // before filter ...
  10. Result result = invoker.invoke(invocation);
  11. // after filter ...
  12. return result;
  13. }
  14. }

META-INF/dubbo/org.apache.dubbo.rpc.Filter:

  1. xxx=com.xxx.XxxFilter

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)