[
]
宙飒zhousa.om 路由配置
网关将接入的请求根据路由策略来指定该请求的转发地址
路由配置示例1:
defaultRouter: clientChannel1 defaultNameSpace:null pipeType: null #本地识别器 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识别失败,或者识别后查找不到匹配的映射项,则尝试使用router2进行路由,检查${pathToken}是否含有"myapp"字符串。如果含有,尝试使用该路由项进行路由,router2没有配置routerKey,则对路由表中的映射项进行条件匹配,如果以“.wsdl”结尾,则选择wsdlService进行路由,如果以“Service.json”结尾,则选择helloworldService进行路由。
当配置routerKey后,routerMap中的映射key应该是静态量或表达式,如果没有配置routerKey,则routerMap中的映射key应该是条件匹配表达式。 |
---|
不论哪种方式,routerMap中的映射项value值都可以是静态常量或者表达式。 |
路由配置示例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,路由到透传渠道,用来解析wsdl文件请求 - id: router3 routerMap: {'${pathToken}->*wsdl': httpTransparentChannel} available: true matcher: '${localPort}->9001 && ${pathToken}->*wsdl' type: default #所有通过9002端口接入的请求,全部路由到http透传渠道 - id: router4 routerMap: {'1->1': httpTransparentChannel} available: true matcher: '${localPort}->9002' type: default #所有通过9003端口接入的请求,全部路由到socket透传渠道 - id: router5 routerMap: {'1->1': socketTransparentChannel} available: true matcher: '${localPort}->9003' type: default #所有通过9004端口接入的请求,socket定长,内容为xml - id: router6 routerMap: {'1->1': socketFixLengthXmlChannel} available: true matcher: '${localPort}->9004' type: default advancedDispatch: false available: true pipeType: direct inbound: true defaultRouter: httpTransparentChannel
还没有评论,来说两句吧...