路由配置

網關将接入的(de)請求根據路由策略來(lái)指定該請求的(de)轉發地(dì / de)址

路由配置示例1:

defaultRouter: clientChannel1
defaultNameSpace:null
pipeType: null
#本地(dì / de)識别器
localRecognizers:

- id: recognizer1
  keyMap: {channelId: '${channelId}'}
  type: map
- id: recognizer2
  keyMap: {pathToken: '${path}'}
  type: url
  values:
- available: true
  id: router1
  routerKey: ${channelId}
  routerMap: {a: helloworldService, b: clientChannel}
- available: true
  id: router2
  matcher: '${pathToken}->*myapp*'
  routerMap: {'${pathToken}->*.wsdl': wsdlService, '${pathToken}->*Service.json': helloworldService}
  type: default

首先嘗試通過router1進行路由,通過map識别器,識别channelId,識别後通過路由表進行靜态映射,假設${channelId}=a,則選擇helloworldService進行路由.

如果channelId識别失敗,或者識别後查找不(bù)到(dào)匹配的(de)映射項,則嘗試使用router2進行路由,檢查${pathToken}是(shì)否含有"myapp"字符串。如果含有,嘗試使用該路由項進行路由,router2沒有配置routerKey,則對路由表中的(de)映射項進行條件匹配,如果以(yǐ)“.wsdl”結尾,則選擇wsdlService進行路由,如果以(yǐ)“Service.json”結尾,則選擇helloworldService進行路由。

當配置routerKey後,routerMap中的(de)映射key應該是(shì)靜态量或表達式,如果沒有配置routerKey,則routerMap中的(de)映射key應該是(shì)條件匹配表達式。
不(bù)論哪種方式,routerMap中的(de)映射項value值都可以(yǐ)是(shì)靜态常量或者表達式。

路由配置示例2:

#全局識别器
recognizer:
  values:

- id: recognizer4
  keyMap: {pathToken: '${path}'}
  type: url
- id: recognizer3
  keyMap: {all: '${all}'}
  type: all
- id: recognizer2
  keyMap: {host: '${host}', path: '${path[2..]}'}
  type: url
- id: recognizer1
  keyMap: {type: '${type}', busiId: '${head.busiId}', version: '${head.version}'}
  type: map
    available: true
    pipeType: direct
    inbound: true
  #路由
  router:
    values:
    #訪問任意http://127.0.0.1:9000/*helloworld.json
- id: router1
  routerMap: {'${pathToken}->*helloworld.json': jsonChannel, '${pathToken}<>*helloworld.json && ${pathToken}->*.json': jsonChannelDynamic}
  available: true
  matcher: '${pathToken}->*.json && ${localPort}->9000'
  type: default
    #訪問任意http://127.0.0.1:9001/*/ws/*
- id: router2
  routerMap: {'${pathToken}->*/ws/*': webserviceOutBoundChannel}
  available: true
  matcher: '${localPort}->9001 && ${pathToken}<>*wsdl'
  type: default
    #訪問任意http://127.0.0.1:9001/*wsdl,路由到(dào)透傳渠道(dào),用來(lái)解析wsdl文件請求
- id: router3
  routerMap: {'${pathToken}->*wsdl': httpTransparentChannel}
  available: true
  matcher: '${localPort}->9001 && ${pathToken}->*wsdl'
  type: default
    #所有通過9002端口接入的(de)請求,全部路由到(dào)http透傳渠道(dào)
- id: router4
  routerMap: {'1->1': httpTransparentChannel}
  available: true
  matcher: '${localPort}->9002'
  type: default
    #所有通過9003端口接入的(de)請求,全部路由到(dào)socket透傳渠道(dào)
- id: router5
  routerMap: {'1->1': socketTransparentChannel}
  available: true
  matcher: '${localPort}->9003'
  type: default
  #所有通過9004端口接入的(de)請求,socket定長,内容爲(wéi / wèi)xml
- id: router6
  routerMap: {'1->1': socketFixLengthXmlChannel}
  available: true
  matcher: '${localPort}->9004'
  type: default
    advancedDispatch: false
    available: true
    pipeType: direct

    inbound: true
    defaultRouter: httpTransparentChannel
Copyright © 屯昌單支科技有限公司 2019 all right reserved,powered by Gitbook聯系方式: wanglihang@mskj.com
修訂時(shí)間: 2019-09-03 17:48:17

results matching ""

    No results matching ""