全局識别器

在(zài)請求報文解析後便開始進行解析,根據配置的(de)識别項,通過識别器類型進行識别,識别後,将識别出(chū)的(de)值作爲(wéi / wèi)上(shàng)下文信息,放入message中 (message作爲(wéi / wèi)上(shàng)下文,攜帶着請求的(de)一(yī / yì /yí)切信息,在(zài)請求鏈中流動的(de)實際就(jiù)是(shì)message),通過在(zài)message的(de)get操作可以(yǐ)獲取。 使用場景: 全局識别器僅識别一(yī / yì /yí)次,對于(yú)整個(gè)流程中在(zài)多個(gè)插件中使用到(dào)的(de)值,應該使用全局識别器進行識别。

本地(dì / de)識别器

配置到(dào)每一(yī / yì /yí)個(gè)處理器中,本地(dì / de)識别器屬于(yú)懶識别類型,隻有在(zài)get操作從上(shàng)下文中獲取不(bù)到(dào)值時(shí),使用本地(dì / de)識别器進行識别,不(bù)同的(de)本地(dì / de)識别器之(zhī)間是(shì)隔離的(de),并且不(bù)會對識别值進行存儲。

使用場景: 在(zài)當前位置使用的(de)值(例如隻在(zài)當前handler中使用),并且不(bù)一(yī / yì /yí)定在(zài)每次請求中都需要(yào / yāo)識别的(de)值,适合使用本地(dì / de)識别器。

識别器中type表示識别器類型,可自定義擴展。

id爲(wéi / wèi)識别器标識,同一(yī / yì /yí)個(gè)handler中不(bù)能重複。

目前默認提供的(de)識别器類型有:

名稱 說(shuō)明
all 全局識别器,返回一(yī / yì /yí)個(gè)固定的(de)常量
router 返回路由的(de)channel id
date 返回時(shí)間格式,如:${yyyy-MM-dd}
header 通過http header中取值
ip 獲取請求者的(de)ip及port,遠端地(dì / de)址: ${ip},遠端端口:${port}, 本機地(dì / de)址: ${localIp}, 本機端口: ${localPort}
map 從請求頭或者請求體中解析參數, 支持多層級解析, 如${root.MsgHeader.MsgTp}, 對多級格式報文的(de)識别配置方式可參考參數映射插件部分
constant 常量識别,直接将表達式值返回,${abc},返回abc
localContext 從GatewayMessage上(shàng)下文中取
uuid 生成uuid随機數,${uuid}
random 生産随機數,給定一(yī / yì /yí)個(gè)bound範围,如${100},生成100内的(de)随機數,${1000},生成1000内的(de)随機數
currentTime 生成一(yī / yì /yí)個(gè)系統時(shí)間戳,${currentTime},調用System.currentTimeMillis()
url 獲取請求者訪問的(de)url信息,支持字段有:“protocol”,“port”,“path”,如${port},${path},
其中path可支持數組選擇,如:http://localhost/pages/editpage.action?pageId=91882673&a=aa
${path},返回:pages/editpage.action?pageId=91882673&a=aa
或者範围選擇,默認使用分隔符/進行分割,可進行自定義,如:
${path[1]}=editpage.action?pageId=91882673&a=aa,
${path(/,?,&)[1]}=editpage.action,
${path(/,?,&)[2]}=pageId=91882673,
${path(/,?,&,=)[3]}=91882673,
範围選擇:
${path(/,?,&)[1..3]} editpage.action/pageId=91882673/a=aa,指定範围
${path(/,?,&)[..2]} pages/editpage.action/pageId=91882673,指定結束位置
${path(/,?,&)[2..]} pageId=91882673/a=aa,指定開始位置

如下爲(wéi / wèi)配置全局識别器示例:

recognizer:
  available: true
  values:

- id: recognizer1
  keyMap: {timestamp: '${timestamp}', aaa: '${aaa}', nonce: '${nonce}', signature: '${signature}',
    bbb: '${bbb}'}
  type: map
- id: recognizer2
  keyMap: {host: '${host}', path: '${path}'}
  type: url
- id: recognizer4
  keyMap: {port: '${port}', ip: '${ip}'}
  type: ip
- id: ioprecognizer
  keyMap: {host: '${host}', iopName: '${path[0]}', projectName: '${path[1]}', protocolName: '${path[2]}',pathService: '${path[2..]}'}
  type: url
- id: epcc_from_wlink_recognizer
  matcher: '${pathNo}->1285'
  keyMap:
    MsgTp: '${root.MsgHeader.MsgTp}'
    TrxCtgy: '${root.MsgBody.TrxInf.TrxCtgy}'
    RPFlg: '${root.MsgBody.RPFlg}'
    Is_Success_Return: '0'
  type: map

如下爲(wéi / wèi)在(zài)handler中配置本地(dì / de)識别器:

inbound_channel:
  values:
  #1、json渠道(dào)
- channelType: inbound
  protocolType: http
  available: true
  inMessagePool: {poolMode: SHARE, corePoolSize: 10, maximumPoolSize: 50, keepAliveTime: 60,
    available: true}
  failOverRetryInterval: 20000
  id: testJson
  localRecognizers:
  - id: a
    type: map
    keyMap:
      gateway_http_request_contentType: json
    matcher: '${gateway_http_uri} -> *login*'
  - id: b
    type: map
    keyMap:
      gateway_http_request_contentType: http-transparent
    matcher: '${gateway_http_uri} -> *transparent*'
    values:
  - {port: 9000, id: testJson, weight: 1, persistent: true, started: true, type: netty, protocolType: http, contentType: json,
    contentRecognition: default, forceCloseConnection: true, inMessageInfoLog: true, contentType: 'json, http-transparent'}
    persistent: true
    name: 總行接入渠道(dào)
    started: true
    outMessagePool: {poolMode: SHARE, corePoolSize: 10, maximumPoolSize: 50, keepAliveTime: 60,
    available: true}

内置變量

引用方式:message.getFromLocalContext(GatewayConstants.GATEWAY_DISPATCHER_CHANNEL_KEY);

因框架内部及方便使用,部分内置變量可直接使用,不(bù)需要(yào / yāo)再通過識别器進行識别,注意,比如 GATEWAY_SEND_REQUEST_TIME等, 隻有在(zài)網關發送消息到(dào)服務端後才能從上(shàng)下文獲取.如下:

變量 變量名 描述
LOCAL_IP localIp 本地(dì / de)ip
LOCAL_PORT localPort 本地(dì / de)端口
REMOTE_IP remoteIp 客戶端遠程訪問者ip
REMOTE_PORT remotePort 客戶端遠程訪問者端口
GATEWAY_EXCEPTION gateway_exception 異常
GATEWAY_MESSAGE_CREATE_TIME_KEY gateway_message_create_time_key 網關收到(dào)客戶端請求時(shí)間
GATEWAY_RECEIVE_REQUEST_TIME gateway_receive_request_time 同上(shàng), 網關收到(dào)客戶端請求時(shí)間
GATEWAY_SEND_REQUEST_TIME gateway_send_request_time 發送消息到(dào)服務端時(shí)間
GATEWAY_RECEIVE_RESPONSE_TIME gateway_receive_response_time 從服務端接受響應時(shí)間
GATEWAY_SEND_RESPONSE_TIME gateway_send_response_time 網關響應回客戶端時(shí)間
GATEWAY_HANDLER_START_TIME_PRE_KEY gatewayhandler_start_time 請求進入每個(gè)插件的(de)時(shí)間, starttime(插件的(de)Id), 對于(yú)異步channel此插件無效
GATEWAY_HANDLER_END_TIME_PRE_KEY gatewayhandler_end_time 請求執行完插件的(de)時(shí)間,endtime(插件id), 對于(yú)異步channel此插件無效
GATEWAY_DISPATCHER_CHANNEL_KEY gateway_dispatcher_channel 路由渠道(dào)
GATEWAY_DISPATCHER_CONNECTOR_KEY gateway_dispatcher_connector 路由連接器
GATEWAY_HTTP_URI_KEY gateway_http_uri 隻有Http請求才能獲取
GATEWAY_HTTP_REQUEST_HEADERS_KEY gateway_http_request_headers 隻有Http請求才能獲取, 是(shì)一(yī / yì /yí)個(gè)http請求頭對象
GATEWAY_REQUEST_MESSAGE_PAYLOAD gateway_request_message_payload http請求報文體Map格式, 一(yī / yì /yí)般情況下響應過程中請求報文會被覆蓋, 可以(yǐ)通過該變量獲取請求報文
Copyright © 屯昌單支科技有限公司 2019 all right reserved,powered by Gitbook聯系方式: wanglihang@mskj.com
修訂時(shí)間: 2019-08-02 16:19:33

results matching ""

    No results matching ""