tencent cloud

文档反馈

触发器事件消息结构汇总

最后更新时间:2024-04-19 16:44:05
    本文档主要汇总所有对接云函数 SCF 的触发器事件的消息结构,触发器配置详情及限制请参考具体的 触发器管理文档
    注意:
    触发器传递的入参事件结构已有部分定义,可直接使用。您可以通过 java cloud event 定义 获取 Java 的库并使用,通过 go cloud event 定义 获取 Golang 的库并使用。

    API 网关触发器的集成请求事件消息结构

    在 API 网关触发器接收到请求时,会将类似以下 JSON 格式的事件数据发送给绑定的 SCF 函数。详情请参见 API 网关触发器
    {
    "requestContext": {
    "serviceId": "service-f94sy04v",
    "path": "/test/{path}",
    "httpMethod": "POST",
    "requestId": "c6af9ac6-****-****-9a41-93e8deadbeef",
    "identity": {
    "secretId": "abdcdxxxxxxxsdfs"
    },
    "sourceIp": "10.0.2.14",
    "stage": "release"
    },
    "headers": {
    "Accept-Language": "en-US,en,cn",
    "Accept": "text/html,application/xml,application/json",
    "Host": "service-3ei3tii4-251000691.ap-guangzhou.apigateway.myqloud.com",
    "User-Agent": "User Agent String"
    },
    "body": "{\\"test\\":\\"body\\"}",
    "pathParameters": {
    "path": "value"
    },
    "queryStringParameters": {
    "foo": "bar"
    },
    "headerParameters":{
    "Refer": "10.0.2.14"
    },
    "stageVariables": {
    "stage": "release"
    },
    "path": "/test/value",
    "queryString": {
    "foo" : "bar",
    "bob" : "alice"
    },
    "httpMethod": "POST"
    }

    Timer 触发器的事件消息结构

    在指定时间触发调用云函数时,会将类似以下的 JSON 格式事件数据发送给绑定的 SCF 云函数。
    {
    "Type":"Timer",
    "TriggerName":"EveryDay",
    "Time":"2019-02-21T11:49:00Z",
    "Message":"user define msg body"
    }

    COS 触发器的事件消息结构

    在指定的 COS Bucket 发生对象创建或对象删除事件时,会将类似以下的 JSON 格式事件数据发送给绑定的 SCF 函数。详情请参见 COS 触发器
    {
    "Records": [{
    "cos": {
    "cosSchemaVersion": "1.0",
    "cosObject": {
    "url": "http://testpic-1253970026.cos.ap-chengdu.myqcloud.com/testfile",
    "meta": {
    "x-cos-request-id": "NWMxOWY4MGFfMjViMjU4NjRfMTUy********ZjM=",
    "Content-Type": ""
    },
    "vid": "",
    "key": "/1253970026/testpic/testfile",
    "size": 1029
    },
    "cosBucket": {
    "region": "cd",
    "name": "testpic",
    "appid": "1253970026"
    },
    "cosNotificationId": "unkown"
    },
    "event": {
    "eventName": "cos:ObjectCreated:*",
    "eventVersion": "1.0",
    "eventTime": 1545205770,
    "eventSource": "qcs::cos",
    "requestParameters": {
    "requestSourceIP": "192.168.15.101",
    "requestHeaders": {
    "Authorization": "q-sign-algorithm=sha1&q-ak=AKIDQm6iUh2NJ6jL41tVUis9KpY5Rgv49zyC&q-sign-time=1545205709;1545215769&q-key-time=1545205709;1545215769&q-header-list=host;x-cos-storage-class&q-url-param-list=&q-signature=098ac7dfe9cf21116f946c4b4c29001c2b449b14"
    }
    },
    "eventQueue": "qcs:0:lambda:cd:appid/1253970026:default.printevent.$LATEST",
    "reservedInfo": "",
    "reqid": 179398952
    }
    }]
    }

    CKafka 触发器的事件消息结构

    在指定的 CKafka Topic 接收到消息时,云函数后台的消费者模块会消费 CKafka Topic 中的消息,并将消息组装为类似以下的 JSON 格式事件,触发绑定的函数并将数据内容作为入参传递给函数。详情请参见 CKafka 触发器
    {
    "Records": [
    {
    "Ckafka": {
    "topic": "test-topic",
    "partition":1,
    "offset":36,
    "msgKey": "None",
    "msgBody": "Hello from Ckafka!"
    }
    },
    {
    "Ckafka": {
    "topic": "test-topic",
    "partition":1,
    "offset":37,
    "msgKey": "None",
    "msgBody": "Hello from Ckafka again!"
    }
    }
    ]
    }

    CMQ Topic 触发器的事件消息结构

    在指定的 CMQ Topic 接受到消息时,会将类似以下的 JSON 格式事件数据发送给绑定的 SCF 函数。详情见 CMQ Topic 触发器
    {
    "Records": [
    {
    "CMQ": {
    "type": "topic",
    "topicOwner":"120xxxxx",
    "topicName": "testtopic",
    "subscriptionName":"xxxxxx",
    "publishTime": "1970-01-01T00:00:00.000Z",
    "msgId": "123345346",
    "requestId":"123345346",
    "msgBody": "Hello from CMQ!",
    "msgTag": "tag1,tag2"
    }
    }
    ]
    }

    CLS 触发器的事件消息结构

    在指定的 CLS 触发器接收到消息时,CLS 的后台消费者模块会消费消息,并将消息组装异步调用您的函数。为保证单次触发传递数据的效率,数据字段的值是 Base64 编码的 ZIP 文档。详情见 CLS 触发器
    {
    "clslogs": {
    "data": "ewogICAgIm1lc3NhZ2VUeXBlIjogIkRBVEFfTUVTU0FHRSIsCiAgICAib3duZXIiOiAiMTIzNDU2Nzg5MDEyIiwKICAgICJsb2dHcm91cCI6I..."
    }
    }
    在解码和解压缩后,日志数据类似以下 JSON 体,以 CLS Logs 消息数据(已解码)为例:
    {
    "topic_id": "xxxx-xx-xx-xx-yyyyyyyy",
    "topic_name": "testname",
    "records": [{
    "timestamp": "1605578090000000",
    "content": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }, {
    "timestamp": "1605578090000003",
    "content": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }]
    }

    MPS 触发器的事件消息结构

    在指定的 MPS 触发器接收到消息时,事件结构与字段以 WorkflowTask 任务为例。详情见 MPS 触发器。示例如下:
    {
    "EventType":"WorkflowTask",
    "WorkflowTaskEvent":{
    "TaskId":"245****654-WorkflowTask-f46dac7fe2436c47******d71946986t0",
    "Status":"FINISH",
    "ErrCode":0,
    "Message":"",
    "InputInfo":{
    "Type":"COS",
    "CosInputInfo":{
    "Bucket":"macgzptest-125****654",
    "Region":"ap-guangzhou",
    "Object":"/dianping2.mp4"
    }
    },
    "MetaData":{
    "AudioDuration":11.261677742004395,
    "AudioStreamSet":[
    {
    "Bitrate":127771,
    "Codec":"aac",
    "SamplingRate":44100
    }
    ],
    "Bitrate":2681468,
    "Container":"mov,mp4,m4a,3gp,3g2,mj2",
    "Duration":11.261677742004395,
    "Height":720,
    "Rotate":90,
    "Size":3539987,
    "VideoDuration":10.510889053344727,
    "VideoStreamSet":[
    {
    "Bitrate":2553697,
    "Codec":"h264",
    "Fps":29,
    "Height":720,
    "Width":1280
    }
    ],
    "Width":1280
    },
    "MediaProcessResultSet":[
    {
    "Type":"Transcode",
    "TranscodeTask":{
    "Status":"SUCCESS",
    "ErrCode":0,
    "Message":"SUCCESS",
    "Input":{
    "Definition":10,
    "WatermarkSet":[
    {
    "Definition":515247,
    "TextContent":"",
    "SvgContent":""
    }
    ],
    "OutputStorage":{
    "Type":"COS",
    "CosOutputStorage":{
    "Bucket":"gztest-125****654",
    "Region":"ap-guangzhou"
    }
    },
    "OutputObjectPath":"/dasda/dianping2_transcode_10",
    "SegmentObjectName":"/dasda/dianping2_transcode_10_{number}",
    "ObjectNumberFormat":{
    "InitialValue":0,
    "Increment":1,
    "MinLength":1,
    "PlaceHolder":"0"
    }
    },
    "Output":{
    "OutputStorage":{
    "Type":"COS",
    "CosOutputStorage":{
    "Bucket":"gztest-125****654",
    "Region":"ap-guangzhou"
    }
    },
    "Path":"/dasda/dianping2_transcode_10.mp4",
    "Definition":10,
    "Bitrate":293022,
    "Height":320,
    "Width":180,
    "Size":401637,
    "Duration":11.26200008392334,
    "Container":"mov,mp4,m4a,3gp,3g2,mj2",
    "Md5":"31dcf904c03d0cd78346a12c25c0acc9",
    "VideoStreamSet":[
    {
    "Bitrate":244608,
    "Codec":"h264",
    "Fps":24,
    "Height":320,
    "Width":180
    }
    ],
    "AudioStreamSet":[
    {
    "Bitrate":48414,
    "Codec":"aac",
    "SamplingRate":44100
    }
    ]
    }
    },
    "AnimatedGraphicTask":null,
    "SnapshotByTimeOffsetTask":null,
    "SampleSnapshotTask":null,
    "ImageSpriteTask":null
    },
    {
    "Type":"AnimatedGraphics",
    "TranscodeTask":null,
    "AnimatedGraphicTask":{
    "Status":"FAIL",
    "ErrCode":30010,
    "Message":"TencentVodPlatErr Or Unkown",
    "Input":{
    "Definition":20000,
    "StartTimeOffset":0,
    "EndTimeOffset":600,
    "OutputStorage":{
    "Type":"COS",
    "CosOutputStorage":{
    "Bucket":"gztest-125****654",
    "Region":"ap-guangzhou"
    }
    },
    "OutputObjectPath":"/dasda/dianping2_animatedGraphic_20000"
    },
    "Output":null
    },
    "SnapshotByTimeOffsetTask":null,
    "SampleSnapshotTask":null,
    "ImageSpriteTask":null
    },
    {
    "Type":"SnapshotByTimeOffset",
    "TranscodeTask":null,
    "AnimatedGraphicTask":null,
    "SnapshotByTimeOffsetTask":{
    "Status":"SUCCESS",
    "ErrCode":0,
    "Message":"SUCCESS",
    "Input":{
    "Definition":10,
    "TimeOffsetSet":[
    
    ],
    "WatermarkSet":[
    {
    "Definition":515247,
    "TextContent":"",
    "SvgContent":""
    }
    ],
    "OutputStorage":{
    "Type":"COS",
    "CosOutputStorage":{
    "Bucket":"gztest-125****654",
    "Region":"ap-guangzhou"
    }
    },
    "OutputObjectPath":"/dasda/dianping2_snapshotByOffset_10_{number}",
    "ObjectNumberFormat":{
    "InitialValue":0,
    "Increment":1,
    "MinLength":1,
    "PlaceHolder":"0"
    }
    },
    "Output":{
    "Storage":{
    "Type":"COS",
    "CosOutputStorage":{
    "Bucket":"gztest-125****654",
    "Region":"ap-guangzhou"
    }
    },
    "Definition":0,
    "PicInfoSet":[
    {
    "TimeOffset":0,
    "Path":"/dasda/dianping2_snapshotByOffset_10_0.jpg",
    "WaterMarkDefinition":[
    515247
    ]
    }
    ]
    }
    },
    "SampleSnapshotTask":null,
    "ImageSpriteTask":null
    },
    {
    "Type":"ImageSprites",
    "TranscodeTask":null,
    "AnimatedGraphicTask":null,
    "SnapshotByTimeOffsetTask":null,
    "SampleSnapshotTask":null,
    "ImageSpriteTask":{
    "Status":"SUCCESS",
    "ErrCode":0,
    "Message":"SUCCESS",
    "Input":{
    "Definition":10,
    "OutputStorage":{
    "Type":"COS",
    "CosOutputStorage":{
    "Bucket":"gztest-125****654",
    "Region":"ap-guangzhou"
    }
    },
    "OutputObjectPath":"/dasda/dianping2_imageSprite_10_{number}",
    "WebVttObjectName":"/dasda/dianping2_imageSprite_10",
    "ObjectNumberFormat":{
    "InitialValue":0,
    "Increment":1,
    "MinLength":1,
    "PlaceHolder":"0"
    }
    },
    "Output":{
    "Storage":{
    "Type":"COS",
    "CosOutputStorage":{
    "Bucket":"gztest-125****654",
    "Region":"ap-guangzhou"
    }
    },
    "Definition":10,
    "Height":80,
    "Width":142,
    "TotalCount":2,
    "ImagePathSet":[
    "/dasda/imageSprite/dianping2_imageSprite_10_0.jpg"
    ],
    "WebVttPath":"/dasda/imageSprite/dianping2_imageSprite_10.vtt"
    }
    }
    }
    ]
    }
    }

    CLB 触发器的事件消息结构

    在 CLB 触发器接收到请求时,会将类似以下 JSON 格式的事件数据发送给绑定的 SCF 函数。详情见 CLB 触发器说明
    {  
      "headers": { 
        "Content-type": "application/json",  
        "Host": "test.clb-scf.com",  
        "User-Agent": "Chrome",  
    
        "X-Stgw-Time": "1591692977.774",  
        "X-Client-Proto": "http",  
        "X-Forwarded-Proto": "http",  
        "X-Client-Proto-Ver": "HTTP/1.1",  
      "X-Real-IP": "9.43.175.219",
        "X-Forwarded-For": "9.43.175.xx"  
    
        "X-Vip": "121.23.21.xx",  
        "X-Vport": "xx",  
        "X-Uri": "/scf_location",  
        "X-Method": "POST"    
        "X-Real-Port": "44347",  
      },  
      "payload": {  
        "key1": "123",  
        "key2": "abc"  
      },
    “isBase64Encoded”:false
    }  

    通过事件总线触发器传递的事件结构

    通过 腾讯云事件总线,可以进一步拓展函数事件触发源,通过事件总线产生的事件将以以下形式发送给云函数,其中"data" 字段里内容由事件源决定,此处以 TDMQ 为例:
    {
    "specversion": "0",
    "id": "13a3f42d-7258-4ada-da6d-023a33******",
    "type": "connector:tdmq",
    "source": "tdmq.cloud.tencent",
    "subjuect": "qcs::tdmq:$region:$account:topicName/$topicSets.clusterId/$topicSets.environmentId/$topicSets.topicName/$topicSets.subscriptionName",
    "time": "1615430559146",
    "region": "ap-guangzhou",
    "datacontenttype": "application/json;charset=utf-8",
    "data": {
    "topic": "persistent://appid/namespace/topic-1",
    "tags": "testtopic",
    "TopicType": "0",
    "subscriptionName": "xxxxxx",
    "toTimestamp": "1603352765001",
    "partitions": "0",
    "msgId": "123345346",
    "msgBody": "Hello from TDMQ!"
    }
    
    联系我们

    联系我们,为您的业务提供专属服务。

    技术支持

    如果你想寻求进一步的帮助,通过工单与我们进行联络。我们提供7x24的工单服务。

    7x24 电话支持