事件网格 EG-过滤规则示例:数值范围匹配

时间:2023-11-01 16:19:48

数值范围匹配

指定某个字段的数值范围。如下表所示,过滤规则只匹配“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                  ]                                    ]           }]  }} 

support.huaweicloud.com/usermanual-eg/eg-ug-019.html