W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
入站流量的規(guī)則
VirtualService是用來處理入站流量的規(guī)則,也就是說用來描述哪些入站流量適用于該路由規(guī)則。
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo:
Field | Type | Description | Required |
---|---|---|---|
name | string | 應(yīng)以 應(yīng)用名/Router類型的方式來命名。name屬性一經(jīng)定義Router類型就確定下來了 | YES |
hosts | string[] | 一般指應(yīng)用名 | NO |
dubbo | DubboRoute[] | dubbo 路由規(guī)則,順序執(zhí)行,符合條件立即返回 | NO |
name | Description |
---|---|
StandardRouter | 完全使用標(biāo)準(zhǔn) VirtualService 描述的 Router |
待補(bǔ)充 | 待補(bǔ)充 |
DubboRoute是VirtualService中的屬性,用來描述路由策略的邊界。
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: #DubboRoute - name: service: fault: mirror: retries: timeout: routedetail:
Field | Type | Description | Required |
---|---|---|---|
name | string | 規(guī)則的名字,方便識(shí)別規(guī)則用意 | NO |
services | StringMatch[] | 規(guī)則生效的服務(wù)名列表,可使用具體的服務(wù)名,也可以使用正則 * 的方式進(jìn)行匹配;默認(rèn)不配置,則代表所有的服務(wù)都生效 | |
fault | dubboFaultInject[] | 故障注入(未實(shí)現(xiàn)) | NO |
mirror | Destination | 鏡像流量(未實(shí)現(xiàn)) | NO |
retries | DubboRetry[] | 重試相關(guān)(未實(shí)現(xiàn)) | NO |
timeout | DubboTimeout[] | 超時(shí)相關(guān)(未實(shí)現(xiàn)) | NO |
routedetail | DubboRouteDetail[] | 具體的流量規(guī)則,順序執(zhí)行,符合條件立即返回 | YES |
DubboRouteDetail用來描述詳細(xì)的路由規(guī)則
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: #DubboRouteDetail - name: match: route: mirror: retries: timeout:
Field | Type | Description | Required |
---|---|---|---|
name | string | 規(guī)則詳情的名字,方便識(shí)別規(guī)則用意 | NO |
match | DubboMatchRequest[] | 匹配條件 | YES |
route | DubboRouteDestination[] | 符合條件的流量的實(shí)際目標(biāo)地址 | YES |
mirror | Destination | 鏡像流量(未實(shí)現(xiàn)) | NO |
retries | DubboRetry[] | 重試相關(guān)(未實(shí)現(xiàn)) | NO |
timeout | DubboTimeout[] | 超時(shí)相關(guān)(未實(shí)現(xiàn)) | NO |
DubboMatchRequest用來描述請(qǐng)求的匹配規(guī)則
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: #DubboMatchRequest - name: method: sourceLabels: attachments: headers: threshold:
Field | Type | Description | Required |
---|---|---|---|
name | string | 匹配規(guī)則名稱 | YES |
method | DubboMethodMatch | 方法相關(guān)的匹配 | YES |
sourceLabels | map<string, string> | 調(diào)用端打的相關(guān) lables, 包含應(yīng)用名、機(jī)器分組、機(jī)器環(huán)境變量信息等; 對(duì)于 HSF-JAVA 來說,可以從上報(bào)的 URL 拿到對(duì)應(yīng)的 key/value | YES |
attachments | DubboAttachmentMatch | 請(qǐng)求附帶的其他信息,比如 HSF 請(qǐng)求上下文、Eagleeye 上下文等 | NO |
headers | map<string, StringMatch> | 通用的請(qǐng)求協(xié)議字段等,如接口名、方法名、超時(shí)等 | NO |
threshold | DoubleMatch | 調(diào)用的 subset 列表的機(jī)器,占整個(gè) host 的閥值 | NO |
由于 headers 、attachemes 、method 之間可能存在字段一樣重復(fù)的情況,TODO 進(jìn)一步細(xì)化
DubboMethodMatch是用來實(shí)現(xiàn)方法的匹配
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - method: #DubboMethodRequest - name_match: argc: args: argp: headers:
Field | Type | Description | Required |
---|---|---|---|
name_match | StringMatch | 匹配請(qǐng)求中的調(diào)用方法名 | YES |
argc | int | 匹配請(qǐng)求的參數(shù)個(gè)數(shù) | NO |
args | DubboMethodArg[] | 為 DubboMethodArg 類型的數(shù)組,表示每個(gè)參數(shù)值需要滿足的條件 | NO |
argp | StringMatch[] | 匹配請(qǐng)求的參數(shù)類型 | NO |
headers | map<string, StringMatch> | 預(yù)留 | NO |
DubboMethodArg用來實(shí)現(xiàn)方法參數(shù)的匹配
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - method: - args: #DubboMethodArg - index: str_value: type: num_value: bool_value: reserve:
Field | Type | Description | Required |
---|---|---|---|
index | uint32 | 匹配參數(shù)的位置,index字段從1開始(即第$index個(gè)參數(shù)) | YES |
type | string | 匹配參數(shù)的類型,以java的 string 類型為例,該字段取值 java.lang.String,該字段默認(rèn)為 java.lang.String | YES |
str_value | ListStringMatch | 匹配參數(shù)的值,根據(jù)$type進(jìn)行解析 ListStringMatcher:匹配 java.lang.String) | NO |
num_value | ListDoubleMatch | 數(shù)值類型匹配 | NO |
bool_value | BoolMatch | bool 值類型匹配 | NO |
reserve | reserve | 復(fù)雜類型的匹配,暫時(shí)不定義 | NO |
DubboAttachmentMatch用來對(duì)任意對(duì)象的完全匹配
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - attachments: #DubboAttachmentMatch eagleeyecontext: dubbocontext:
Field | Type | Description | Required |
---|---|---|---|
eagleeyecontext | map<string, StringMatch> | 鷹眼上下文 | NO |
dubbocontext | map<string, StringMatch> | Dubbo 請(qǐng)求上下文 | NO |
ListStringMatch是一組StringMatch集合,任何一個(gè) StringMatch匹配則匹配
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - method: - args: - index: 1 str_value: #ListStringMatch oneof: - regex: "*abc*" - exact: parameter-1
Field | Type | Description | Required |
---|---|---|---|
oneof | StringMatch[] | 任何一個(gè)StringMatch匹配則匹配 | NO |
StringMatch用來描述字符串匹配規(guī)則
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - service: #StringMatch - exact: org.apache.dubbo.demoService:1.0.0 - prefix: org.apache.dubbo.hello - regex: org.apache.dubbo.*Service:2.0.0
Field | Type | Description | Required |
---|---|---|---|
exact | string (oneof) | 完全匹配 | NO |
prefix | string (oneof) | 前綴匹配 | NO |
regex | string (oneof) | 正則匹配 | NO |
noempty | string (oneof) | 非空字符匹配 | NO |
empty | string (oneof) | 空字符匹配 | NO |
ListDoubleMatch是一組DoubleMatch集合,任何一個(gè) DoubleMatch匹配則匹配參數(shù)
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - method: - args: - index: 1 type: java.lang.Double num_value: #ListDoubleMatch oneof: - range: start: 1 end: 100
Field | Type | Description | Required |
---|---|---|---|
oneof | DoubleMatch[] | 任何一個(gè)DoubleMatch匹配則匹配 | NO |
DoubleMatch用于匹配 int, long, double類型的數(shù)值
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - method: - args: - index: 1 type: java.lang.Double num_value: oneof: #DoubleMatch[] - range: start: 1 end: 100 #假設(shè)當(dāng)前輸入的Double類型的參數(shù)值為x, #則下面表達(dá)式的意思是:x%mode=exact, #即當(dāng)x%10=6才匹配 - exact: 6 mode: 10
Field | Type | Description | Required |
---|---|---|---|
exact | double(oneof) | 數(shù)值完全匹配 | NO |
range | DoubleRangeMatch(oneof) | 數(shù)值范圍匹配 | NO |
mode | double | 取模操作,需要與上面兩個(gè)語義一起配置使用 | NO |
DoubleRangeMatch是對(duì)double值的范圍進(jìn)行匹配
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - method: - args: - index: 1 type: java.lang.Double num_value: oneof: - range: #DoubleRangeMatch start: 1.2 end: 1000.5
Field | Type | Description | Required |
---|---|---|---|
start | double | 數(shù)值大于或等于 | YES |
end | double | 數(shù)值小于 | YES |
BoolMatch用來對(duì)true, false的完全匹配
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - method: - args: - index: 1 type: java.lang.Boolean bool_value: #BoolMatch - exact: true
Field | Type | Description | Required |
---|---|---|---|
exact | bool(oneof) | true, false ,完全匹配 |
ObjectMatch用來對(duì)任意對(duì)象的完全匹配
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - match: - method: - args: - index: 1 type: java.lang.String str_value: oneof: - regex: "*abc*" - exact: parameter-1
Field | Type | Description | Required |
---|---|---|---|
type | string | 匹配參數(shù)的類型,以java的 string 類型為例,該字段取值 java.lang.String,該字段默認(rèn)為 java.lang.String | YES |
str_value | ListStringMatch | 匹配參數(shù)的值,根據(jù)$type進(jìn)行解析 ListStringMatcher:匹配 java.lang.String) | NO |
num_value | ListDoubleMatch | NO | |
bool_value | BoolMatch | NO |
DubboRouteDestination用來描述流量到目標(biāo)地址的策略
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - route: #DubboRouteDestination destination: weight: 50
Field | Type | Description | Required |
---|---|---|---|
destination | DubboDestination | 路由目標(biāo) Destination | YES |
weight | int | 路由權(quán)重 | NO |
DubboDestination用來描述路由流量的目標(biāo)地址
apiVersion: service.dubbo.apache.org/v1alpha1 kind: VirtualService metadata: name: demo/StandardRouter spec: hosts: dubbo: - routedetail: - route: #DubboRouteDestination destination: host: subnet: port: fallback:
Field | Type | Description | Required |
---|---|---|---|
host | string | 注冊(cè)中心里面對(duì)應(yīng)的key值,現(xiàn)在是接口名 | YES |
subset | string | 地址列表 | YES |
port | int | 端口號(hào) | YES |
fallback | DubboDestination | fallback到的另外一個(gè)地址列表 | NO |
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: