呼叫攔截擴充
擴展說明
服務提供者和服務消費者呼叫過程攔截。Dubbo 本身的大多數功能都是基於此擴展點實現的。每次執行遠端方法時,都會執行此攔截。請注意對效能的影響。
協議
- 使用者自訂過濾器預設位於內建過濾器之後。
- 特殊值
default
表示插入預設擴展點的位置。例如:filter="xxx,default,yyy"
表示xxx
在預設過濾器之前,而yyy
在預設過濾器之後。 - 特殊符號
-
表示剔除。例如:filter="-foo1"
,排除添加預設擴展點foo1
。例如:filter="-default"
,移除所有預設擴展點。 - 當提供者和服務同時配置過濾器時,所有過濾器都會累加而不是覆蓋。例如:
<dubbo:provider filter="xxx,yyy"/>
和<dubbo:service filter="aaa,bbb" />
,則xxx
、yyy
、aaa
、bbb
都會生效。如果要覆蓋,則需要配置:<dubbo:service filter="-xxx,-yyy,aaa,bbb" />
擴展埠
org.apache.dubbo.rpc.Filter
擴展配置
<!-- 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"/>
已知擴展
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
擴展範例
Maven 專案結構
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
上次修改時間:2023 年 1 月 2 日:增強英文文件 (#1798) (95a9f4f6c1c)