Extension for intercepting the invocation for both service provider and consumer, furthermore, most of functions in dubbo are implemented base on the same mechanism. Since every time when remote method is invoked, the filter extensions will be executed too, the corresponding penalty should be considered before more filters are added.
Contract:
default is introduced to represent the default extension location. For example: for filter="xxx,default,yyy", xxx is before default filter, and yyy is after the default filter.- means delete. For example: filter="-foo1" excludes foo1 extension. For example, filter="-default" exclues all default filters.<dubbo:provider filter="xxx,yyy"/> and <dubbo:service filter="aaa,bbb" />,xxx, yyy, aaa, bbb are all count as filters. In order to change to override, use: <dubbo:service filter="-xxx,-yyy,aaa,bbb" />org.apache.dubbo.rpc.Filter
<!-- filter for consumer -->
<dubbo:reference filter="xxx,yyy" />
<!-- default filter configuration for the consumer, will intercept for all references -->
<dubbo:consumer filter="xxx,yyy"/>
<!-- filter for provider -->
<dubbo:service filter="xxx,yyy" />
<!-- default filter configuration for the provider, will intercept for 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.DeprecatedFilterDirectory layout:
src
|-main
|-java
|-com
|-xxx
|-XxxFilter.java (Filter implementation)
|-resources
|-META-INF
|-dubbo
|-org.apache.dubbo.rpc.Filter (plain text file with the 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