事件
事件是符合特定规范的数据。事件源发布到事件网格的事件必须符合CloudEvents规范。
事件网格EventGrid基于KMS服务进行静态加密,默认自动加密所有存储数据及元数据,无需额外配置即可满足数据安全和合规要求,且不收取额外费用。
事件网格支持的事件如下。
- 华为云服务事件:华为云服务事件源产生的事件。
- 自定义事件:您自定义的事件源接入事件网格产生的事件。您需要自行使用SDK接入事件网格。
约束与限制
- 单事件大小限制:64K。
- 单条请求所有事件总大小限制:256K。
- 单条请求事件数量限制:20条。
事件示例
事件源发布到事件网格的事件示例如下:
{
"events":[{
"id": "4b26115b-778e-11ec-833e-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"
}
}]
} 示例中涉及的参数说明如表1所示。
参数 | 类型 | 是否必选 | 示例值 | 说明 |
|---|---|---|---|---|
id | String | 是 | 4b26115b-778e-*******-833e-cf74af | 事件ID。标识事件的唯一值。 |
specversion | String | 是 | 1.0 | CloudEvents协议版本。 |
source | String | 是 | HC.OBS | 事件源。标明事件的来源。 |
type | String | 是 | object:put | 事件类型。标明与事件源相关的事件类型。 |
datacontenttype | String | 否 | application/json | 参数“data”的内容格式。 目前只支持application/json格式。 |
subject | String | 否 | xxx.jpg | 事件主题。标明事件具体的主题形式。 |
time | Timestamp | 否 | 2022-01-17T12:07:48.955Z | 事件产生的时间。 |
data | Struct | 否 | {
"name": "test01",
"state": "enable"
} | 事件内容。JSON对象格式。 |
事件批量发送
事件批量发送请求体的示例如下:
{
"events":[{
"id": "eg-test-001",
"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"
}
},
{
"id": "eg-test-002",
"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"
}
},
{
"id": "eg-test-003",
"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"
}
},...]
} 全部成功的返回体:
{"failed_count":0,"events":[{"error_code":null,"error_msg":null,"event_id":"eg-test-003"},{"error_code":null,"error_msg":null,"event_id":"eg-test-003"},{"error_code":null,"error_msg":null,"event_id":"eg-test-002"}]} 状态码:200
单条请求的事件数量超出限制的返回体:
{"failed_count":1,"events":[{"error_code":"00533013","error_msg":"Too many events for a request.","event_id":"eg-test-003"},{"error_code":null,"error_msg":null,"event_id":"eg-test-003"},{"error_code":null,"error_msg":null,"event_id":"eg-test-002"}]} 状态码:400
单条事件的大小超出限制的返回体:
{"failed_count":3,"events":[{"error_code":00533012,"error_msg":An event is too large."event_id":"eg-test-003"},{"error_code":00533012,"error_msg":the number of events exceeds the limit,"event_id":"eg-test-003"},{"error_code":00533012,"error_msg":the number of events exceeds the limit,"event_id":"eg-test-002"}]} 状态码:400
单条请求所有事件的总大小超出了限制
{"error_code":"00533007","error_msg":"The total size of a request's all events is too large.","error_detail":"The total size of a request's all events is too large."}
{"error_code":"00533012","error_msg":"An event is too large.","error_detail":"An event is too large."}
{"error_code":"00533013","error_msg":"Too many events for a request.","error_detail":"Too many events for a request."} 状态码:400

状态码为400的情况:
- 单条请求所有事件的总大小超出了限制。(错误码:EG.00533007;错误信息:The total size of a request's all events is too large)
- 单条请求的事件数量超出了限制。(错误码:EG.00533013;错误信息:Too many events for a request)

