云服务器内容精选

  • 匹配规则 过滤规则和事件匹配时,需要遵循以下规则: 顶级匹配字段只支持source、type、subject、data。 顶级匹配必须包括source字段,且source只支持StringIn操作符。 data字段最多支持5个任意匹配字段,每个匹配字段最多嵌套5级。 每个匹配字段的匹配条件最多支持5个,多个匹配条件间是“或”的关系。 多个匹配字段间是“并且”的关系。 同一层级相同的匹配字段定义多次,则以最后一次为准。
  • 运算操作符 过滤规则和事件匹配时,使用的运算操作符如表1所示。 表1 运算操作符列表 操作符 输入值 条件值 说明 StringIn String/String[] String[] values 检查输入值是否与任一条件值完全匹配 StringNotIn String/String[] String[] values 检查输入值是否与所有条件值都不匹配 StringStartsWith String/String[] String[] values 检查输入值是否与任一条件值前缀匹配 StringNotStartsWith String/String[] String[] values 检查输入值是否与所有条件值前缀都不匹配 StringEndsWith String/String[] String[] values 检查输入值是否与任一条件值后缀匹配 StringNotEndsWith String/String[] String[] values 检查输入值是否与所有条件值后缀都不匹配 NumberIn Number/Number[] Number[] values 检查输入值是否与任一条件值完全匹配 NumberNotIn Number/Number[] Number[] values 检查输入值是否与所有条件值都不匹配 NumberLessThan Number/Number[] Number value 检查输入值是否与小于条件值 NumberNotLessThan Number/Number[] Number value 检查输入值是否与不小于(大于或等于)条件值 NumberGreaterThan Number/Number[] Number value 检查输入值是否与大于条件值 NumberNotGreaterThan Number/Number[] Number value 检查输入值是否与不大于(小于或等于)条件值 NumberInRange Number/Number[] Number[][] values 检查输入值是否在任一条件范围值内 NumberNotInRange Number/Number[] Number[][] values 检查输入值是否不在任一条件范围值内 IsNull - 无 检查输入值是否为null或未定义 IsNotNull - 无 检查输入值是否不为null或未定义 IsTrue Boolean 无 检查输入值是否为true IsNotTrue Boolean 无 检查输入值是否不为true,即false
  • 匹配字段 过滤规则和事件匹配时,使用的匹配字段如表3所示。 表3 匹配字段列表 字段名 条件值类型 示例说明 source JSON对象数组 事件源,条件值位于JSON数组中,source字段只支持“StringIn” 示例: [{“op”: “StringIn”, “values”: [“HC.OBS”]}] type JSON对象数组 事件类型,条件值位于JSON数组中 示例: [{“op”: “StringIn”, “values”: [“object:put”]}] subject JSON对象数组 事件主体,条件值位于JSON数组中 示例: [{“op”: “StringEndsWith”, “values”: [“.jpg”]}] data JSON对象 事件数据,条件值位于JSON对象中,条件值为子匹配字段,支持最多5层嵌套结构 示例: {“state”: [{“op”: “StringIn”, “values”: [“running”]}]
  • 透传 事件网格不对事件进行转换,将CloudEvents标准事件直接路由到事件目标。示例如下: 转换前的事件 转换类型 转换后的事件 { "events":[{ "id": "4b26115b-73e-cf74a******", "specversion": "1.0", "source": "HC.OBS", "type": "object:put", "datacontenttype": "application/json", "subject": "xxx.jpg", "time": "2022-01-17T12:07:48.955Z", "data": { "name": "test01", "state": "enable" } }] } 透传 { "events":[{ "id": "4b26115b-73e-cf74******", "specversion": "1.0", "source": "HC.OBS", "type": "object:put", "datacontenttype": "application/json", "subject": "xxx.jpg", "time": "2022-01-17T12:07:48.955Z", "data": { "name": "test01", "state": "enable" } }] }
  • 其他示例 在创建事件订阅-配置事件源为“分布式消息服务RabbitMQ版”或“分布式消息服务RocketMQ版”,消息转换为CloudEvents格式事件后,data字段下将包含context字段,在创建事件订阅-配置事件目标,规则类型配置为“变量”时,规则必须包含context字段,示例如下: 转换前的事件 转换类型 转换后的事件 { "type": "ROCKETMQ:CloudTrace:RocketmqCall", "data": { "context": { "name": "test01", "state": "enable" } }, "source": "zhang_roc", "time": "2023-02-01T10:47:07Z", "datacontenttype": "application/json", "specversion": "1.0", "id": "2f885496-570c-4925-82fd-d1ad09******", "subject": "ROCKETMQ:cn-north-7:eec88b34-9470-483e-8961-edb168******/0de095e33e00d36e2fd2c0019a******:ROCKETMQ:zhang_roc" } 参数 {"name":"$.data.context.name"} 模板 My name is ${name} My name is test01 在创建事件订阅-配置事件目标,事件目标配置为“FunctionGraph(函数计算)”时,若内容转换规则配置为“透传”,无法将事件内容作为输入值传递至事件目标。如需将事件内容作为函数流输入值,可以通过“变量”或“常量”的内容转换规则,规则必须包含input字段,示例如下: 表1 变量示例 转换前的事件 规则配置 转换后的事件 { "events":[{ "id": "4b26115b-73cf74a******", "specversion": "1.0", "source": "HC.OBS", "type": "object:put", "datacontenttype": "application/json", "subject": "xxx.jpg", "time": "2022-01-17T12:07:48.955Z", "data": { "name": "test01", "state": "enable" } }] } 变量 {"data": "$.data"} 模板 {"input": ${data}} { "input": { "name": "test01", "state": "enable" } } 表2 常量示例 转换前的事件 规则配置 转换后的事件 { "events":[{ "id": "4b26115b-73cf74a******", "specversion": "1.0", "source": "HC.OBS", "type": "object:put", "datacontenttype": "application/json", "subject": "xxx.jpg", "time": "2022-01-17T12:07:48.955Z", "data": { "name": "test01", "state": "enable" } }] } 常量 { "input": { "name": "test01" } } { "input": { "name": "test01" } }
  • 常量 事件只能触发事件目标,但是不会传送事件内容到事件目标,事件网格将您设置的常量路由到事件目标。示例如下: 转换前的事件 规则配置 转换后的事件 { "events":[{ "id": "4b26115b-73cf74a******", "specversion": "1.0", "source": "HC.OBS", "type": "object:put", "datacontenttype": "application/json", "subject": "xxx.jpg", "time": "2022-01-17T12:07:48.955Z", "data": { "name": "test01", "state": "enable" } }] } 参数 test01 说明: 当事件目标为“FunctionGraph(函数计算)”,规则配置参数需为JSON格式,示例如下: {"name": "test01"} test01 说明: 当事件目标为“FunctionGraph(函数计算)”,转换后的事件结果如下: {"name": "test01"}
  • 操作步骤: 创建事件通道。 图2 创建事件通道 创建rocketmq事件源。 图3 创建rocketmq事件源 创建rocketmq事件订阅。 图4 创建rocketmq事件订阅 创建事件订阅成功后rocketmq事件源变为运行中 图5 创建事件订阅 发送事件。 图6 发送事件 查看事件消息格式。 查看事件轨迹的事件详情: 图7 查看事件详情 消息体事件格式如下: { "datacontenttype": "application/json", "data": { "context": "{\"hello\":\"world\"}", "topic": "topic-test" }, "subject": "ROCKETMQ:cn-north-4:f003dc69-2fc3-4c44-9062-0b9a2c6cb8cc/0ef1e7a03280f3ed2f69c00c652a5744:ROCKETMQ:source-rocketmq", "specversion": "1.0", "id": "e6cc599b-0664-4078-87dd-5630087d5f7e", "source": "source-rocketmq", "time": "2024-02-05T14:20:31Z", "type": "ROCKETMQ:CloudTrace:RocketmqCall" } 查看目标函数日志: 图8 查看目标函数日志
  • 后缀匹配 指定某个字段的值进行后缀匹配。如下表所示,过滤规则只匹配“subject”字段以“jpg”结尾的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable"} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "subject": [{ "op": "StringEndsWith", "values": ["jpg"]}]} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable"} }]}
  • 后缀不匹配 指定某个字段的值进行后缀不匹配。如下表所示,过滤规则只匹配“subject”字段不以“txt”结尾的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable"} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "subject":[{ "op": "StringNotEndsWith", "values": ["txt"]}]} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable"} }]}
  • 前缀匹配 指定某个字段的值进行前缀匹配。如下表所示,过滤规则只匹配“type”字段以“object:”开头的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable"} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "type": [{ "op": "StringStartsWith", "values": ["object:"]}]} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable"} }]}
  • 前缀不匹配 指定某个字段的值进行前缀不匹配。如下表所示,过滤规则只匹配“source”字段不以“HC”开头的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable"} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "source": [{ "op": "StringNotStartsWith", "values": ["HC"]}]} 无
  • 数值范围匹配 指定某个字段的数值范围。如下表所示,过滤规则只匹配“data”下“size”字段小于20的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "size":[{ "op": "NumberLessThan", "value":20 }] }} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} 如下表所示,过滤规则只匹配“data”下“size”字段大于等于2的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "size":[{ "op": "NumberNotLessThan", "value":2 }] }} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} 如下表所示,过滤规则只匹配“data”下“size”字段大于9的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "size":[{ "op": "NumberGreaterThan", "value":9 }] }} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} 如下表所示,过滤规则只匹配“data”下“size”字段不大于9的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "size":[{ "op": "NumberNotGreaterThan", "value":9 }] }} 无 如下表所示,过滤规则只匹配“data”下“size”字段取值在1到20之间的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "size":[{ "op": "NumberInRange", "values":[ [ 1, 20 ] ] }] }} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} 如下表所示,过滤规则只匹配“data”下“size”字段取值小于1或大于20的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "size":[{ "op": "NumberNotInRange", "values":[ [ 1, 20 ] ] }] }} 无
  • 不为true匹配 检查某个字段的值是否不为true。如下表所示,过滤规则只匹配“data”下存在“name”字段取值不为true的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size": null} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "name":[{ "op": "IsNotTrue" }] }} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size": null} }]}
  • 空值匹配 检查某个字段的值是否为null或未定义。如下表所示,过滤规则只匹配“data”下“size”和“age”字段取值为null或未定义的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size": null} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "size":[{ "op": "IsNull" }], "age":[{ "op": "IsNull" }] }} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":null} }]}
  • 非空匹配 检查某个字段的值是否不为null。如下表所示,过滤规则只匹配“data”下“size”和“name”字段取值不为null的事件。 从事件源接收的事件 过滤规则 过滤后的事件 { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size": 10} }]} { "source": [{ "op": "StringIn", "values": ["HC.OBS"]}], "data":{ "size":[{ "op": "IsNotNull" }], "name":[{ "op": "IsNotNull" }] }} { "events":[{"id": "4b26115b-778e-11ec-******", "specversion": "1.0","source": "HC.OBS","type": "object:put","datacontenttype": "application/json","subject": "xxx.jpg","time": "2022-01-17T12:07:00.955Z","data": {"name": "test01","state": "enable", "size":10} }]}