背景信息
事件總線EventBridge支持的事件內(nèi)容轉(zhuǎn)換類型如下:
完整事件
當(dāng)轉(zhuǎn)化類型為完整事件時(shí),事件總線EventBridge不對(duì)事件進(jìn)行轉(zhuǎn)換,將原生CloudEvents的完整結(jié)構(gòu)路由到事件目標(biāo)。下表介紹經(jīng)過完整事件轉(zhuǎn)換前后的事件示例。
轉(zhuǎn)換前的事件 | 轉(zhuǎn)換類型 | 轉(zhuǎn)換后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.com/test.json",
"subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time":"2020-08-17T16:04:46.149Asia/Shanghai",
"aliyuneventbusname":"demo-bus",
"aliyunregionid":"Shanghai",
"data":{
"name":"test",
"scope":100
}
}
| 完整事件 | {
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.com/test.json",
"subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time":"2020-08-17T16:04:46.149Asia/Shanghai",
"aliyuneventbusname":"demo-bus",
"aliyunregionid":"Shanghai",
"data":{
"name":"test",
"scope":100
}
}
|
部分事件
當(dāng)轉(zhuǎn)換類型為部分事件時(shí),事件總線EventBridge通過JSONPath從CloudEvents中提取事件中的參數(shù),將指定的事件內(nèi)容路由到事件目標(biāo)。下表介紹經(jīng)過部分事件轉(zhuǎn)換前后的事件示例。
轉(zhuǎn)換前的事件 | 轉(zhuǎn)換類型 | 轉(zhuǎn)換后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.com/test.json",
"subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time":"2020-08-17T16:04:46.149Asia/Shanghai",
"aliyuneventbusname":"demo-bus",
"aliyunregionid":"Shanghai",
"data":{
"name":"test",
"scope":100
}
}
| 部分事件 $.data.name
說明 部分事件只支持定義一個(gè)變量。 value不超過10240個(gè)字符。
| test
|
常量
當(dāng)轉(zhuǎn)換類型為常量時(shí),事件只起到觸發(fā)器的作用,不管事件內(nèi)容是什么,事件總線EventBridge都把常量路由到事件目標(biāo)。下表介紹經(jīng)過常量轉(zhuǎn)換前后的事件示例。
轉(zhuǎn)換前的事件 | 轉(zhuǎn)換類型 | 轉(zhuǎn)換后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.com/test.json",
"subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time":"2020-08-17T16:04:46.149Asia/Shanghai",
"aliyuneventbusname":"demo-bus",
"aliyunregionid":"Shanghai",
"data":{
"name":"test",
"scope":100
}
}
| 常量 test1
| test1
|
模板
當(dāng)轉(zhuǎn)換類型為模板時(shí),通過自定義模板、定義模板里需要的變量,事件總線EventBridge通過JSONPath從CloudEvents提取事件中的參數(shù),把這些值存放在變量中,然后按照模板定義的格式路由到事件目標(biāo)。下表介紹經(jīng)過模板轉(zhuǎn)換前后的事件示例。
轉(zhuǎn)換前的事件 | 轉(zhuǎn)換類型 | 轉(zhuǎn)換后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.com/test.json",
"subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time":"2020-08-17T16:04:46.149Asia/Shanghai",
"aliyuneventbusname":"demo-bus",
"aliyunregionid":"Shanghai",
"data":{
"name":"test",
"scope":100
}
}
| 模板 變量 {
"name":"$.data.name",
"constant":"Please deal with it timely."
}
模板 The instance is broken,which name is ${name}, ${constant}
| The instance is broken,which name is test, Please deal with it timely.
|
您也可以創(chuàng)建String格式和JSON格式的模板,通過自定義模板將事件轉(zhuǎn)換成示例輸出,然后路由到事件目標(biāo)。以下為事件總線EventBridge支持的模板類型:
表 1. 簡(jiǎn)單String
轉(zhuǎn)換前的事件 | 轉(zhuǎn)換類型 | 轉(zhuǎn)換后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.com/test.json",
"subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time":"2020-08-17T16:04:46.149Asia/Shanghai",
"aliyuneventbusname":"demo-bus",
"aliyunregionid":"Shanghai",
"data":{
"name":"test",
"state":"RUNNING"
}
}
| 模板 | "name test is in RUNNING"
|
表 2. 簡(jiǎn)單JSON
轉(zhuǎn)換前的事件 | 轉(zhuǎn)換類型 | 轉(zhuǎn)換后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.com/test.json",
"subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time":"2020-08-17T16:04:46.149Asia/Shanghai",
"aliyuneventbusname":"demo-bus",
"aliyunregionid":"Shanghai",
"data":{
"name":"test",
"state":"RUNNING"
}
}
| 模板 變量 {
"name":"$.data.name",
"state":"$.data.state"
}
模板 {
"name":"${name}",
"state":"${state}"
}
| {
"name":"test",
"state":"RUNNING"
}
|
表 3. 混合變量和常量的JSON
轉(zhuǎn)換前的事件 | 轉(zhuǎn)換類型 | 轉(zhuǎn)換后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.com/test.json",
"subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
"time":"2020-08-17T16:04:46.149Asia/Shanghai",
"aliyuneventbusname":"demo-bus",
"aliyunregionid":"Shanghai",
"data":{
"name":"test",
"state":"RUNNING"
}
}
| 模板 變量 {
"name":"$.data.name",
"state":"$.data.state"
}
模板 {
"name":"${name}",
"state":[
9,
"${state}",
true
],
"Transformed":"Yes"
}
| {
"name":"test",
"state":[
9,
"RUNNING",
true
],
"Transformed":"Yes"
}
|
表 4. 嵌套JSON
轉(zhuǎn)換前的事件 | 轉(zhuǎn)換類型 | 轉(zhuǎn)換后的事件 |
{
"id": "45ef4dewdwe1-7c35-447a-bd93-fab****",
"source": "acs.imm",
"specversion": "1.0",
"subject": "acs.imm:cn-hangzhou:123456789098****:215672",
"time": "2020-11-19T21:04:41+08:00",
"type": "imm:FileMeta:Index",
"aliyunaccountid": "123456789098****",
"aliyunpublishtime": "2020-11-19T21:04:42.179PRC",
"aliyuneventbusname": "default",
"aliyunregionid": "cn-hangzhou",
"aliyunpublishaddr": "172.25.XX.XX",
"data": {
"ProjectName": "test_project",
"DatasetName": "test_dataset",
"RequestId": "D2A3AE88-D17C-4CCC-B149-6651115C****",
"StartTime": "2021-07-22T14:03:15.489885+08:00",
"EndTime": "2021-07-22T14:05:15.489885+08:00",
"Message": "InvalidParameter",
"Success": false,
"Files": [
{
"URI": "oss://bucket/file",
"CustomId": "defaultId",
"CustomLabels": {
"Key1": "Val1",
"Key2": "Val2"
},
"Error": "InternalError"
}
]
}
}
| 模板 變量 {
"ProjectName":"$.data.ProjectName",
"Files":"$.data.Files"
}
模板 {
"ProjectName":"${ProjectName}",
"Files":${Files}
}
| {
"ProjectName":"test_project",
"Files": [
{
"URI": "oss://bucket/file",
"CustomId": "defaultId",
"CustomLabels": {
"Key1": "Val1",
"Key2": "Val2"
},
"Error": "InternalError"
}
]
}
|
在模板中支持2個(gè)處理特殊字符的函數(shù)分別是jsonEscape和htmlEscape。