函数工作流 FUNCTIONGRAPH-FunctionGraph支持的触发事件:示例事件

时间:2024-12-16 16:26:17

示例事件

  • SMN 示例事件
    {
        "record": [
            {
                "event_version": "1.0",
                "smn": {
                    "topic_urn": "urn:smn:{region}:0162c0f220284698b77a3d264376343a:{function_name}",
                    "timestamp": "2018-01-09T07:11:40Z",
                    "message_attributes": null,
                    "message": "this is smn message content",
                    "type": "notification",
                    "message_id": "a51671f77d4a479cacb09e2cd591a983",
                    "subject": "this is smn message subject"
                },
                "event_subscription_urn": "urn:fss:{region}:0162c0f220284698b77a3d264376343a:function:default:read-smn-message:latest",
                "event_source": "smn"
            }
    ],
        "functionname": "test",
        "requestId": "7c307f6a-cf68-4e65-8be0-4c77405a1b2c",
        "timestamp": "Wed Nov 15 2017 12:00:00 GMT+0800 ( CS T)"
    }
    表1 参数说明

    参数

    类型

    示例值

    描述

    event_version

    String

    1.0

    事件协议的版本。

    topic_urn

    String

    参考示例

    SMN事件唯一编号

    type

    String

    notification

    事件的类型

    RequestID

    String

    7c307f6a-cf68-4e65-8be0-4c77405a1b2c

    请求ID。每个请求的ID取值唯一。

    message_id

    String

    a51671f77d4a479cacb09e2cd591a983

    消息ID。每条消息的ID取值唯一。

    Message

    String

    this is smn message content

    消息内容

    event_source

    String

    smn

    事件源

    event_subscription_urn

    String

    参考示例

    添加的订阅唯一编号

    timestamp

    String

    Wed Nov 15 2017 12:00:00 GMT+0800 (CST)

    事件发生的时间

  • APIG示例事件
    {
        "body": "{\"test\":\"body\"}",
        "requestContext": {
            "apiId": "bc1dcffd-aa35-474d-897c-d53425a4c08e",
            "requestId": "11cdcdcf33949dc6d722640a13091c77",
            "stage": "RELEASE"
        },
        "queryStringParameters": {
            "responseType": "html"
        },
        "httpMethod": "GET",
    "pathParameters": {
    "path":"value"
    },
        "headers": {
            "accept-language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
            "accept-encoding": "gzip, deflate, br",
            "x-forwarded-port": "443",
            "x-forwarded-for": "103.218.216.98",
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
            "upgrade-insecure-requests": "1",
            "host": "50eedf92-c9ad-4ac0-827e-d7c11415d4f1.apigw.region.cloud.com",
            "x-forwarded-proto": "https",
            "pragma": "no-cache",
            "cache-control": "no-cache",
            "x-real-ip": "103.218.216.98",
            "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0"
        },
        "path": "/apig-event-template",
        "isBase64Encoded": true
    }
    • 通过APIG服务调用函数服务时,isBase64Encoded的值默认为true,表示APIG传递给FunctionGraph的请求体body已经进行Base64编码,需要先对body内容Base64解码后再处理。
    • 函数必须按以下结构返回字符串。
      {
          "isBase64Encoded": true|false,
          "statusCode": httpStatusCode,
          "headers": {"headerName":"headerValue",...},
          "body": "..."
      }
    表2 参数说明

    参数

    类型

    示例值

    描述

    body

    String

    "{\"test\":\"body\"}"

    记录实际请求转换为String字符串后的内容。

    requestContext

    Map

    参考示例

    请求来源的API网关的配置信息、请求标识、认证信息、来源信息。

    httpMethod

    String

    GET

    记录实际请求的HTTP方法

    queryStringParameters

    Map

    参考示例

    记录在API网关中配置过的Query参数以及实际取值。

    pathParameters

    Map

    参考示例

    记录在API网关中配置过的Path参数以及实际取值。

    headers

    Map

    参考示例

    记录实际请求的完整Header内容

    path

    String

    /apig-event-template

    记录实际请求的完整的Path信息

    isBase64Encoded

    Boolean

    True

    默认为true

  • DIS示例事件
    {
        "ShardID": "shardId-0000000000",
        "Message": {
            "next_partition_cursor": "eyJnZXRJdGVyYXRvclBhcmFtIjp7InN0cmVhbS1uYW1lIjoiZGlzLXN3dGVzdCIsInBhcnRpdGlvbi1pZCI6InNoYXJkSWQtMDAwMDAwMDAwMCIsImN1cnNvci10eXBlIjoiVFJJTV9IT1JJWk9OIiwic3RhcnRpbmctc2VxdWVuY2UtbnVtYmVyIjoiNCJ9LCJnZW5lcmF0ZVRpbWVzdGFtcCI6MTUwOTYwNjM5MjE5MX0",
            "records": [
                {
                    "partition_key": "shardId_0000000000",
                    "data": "d2VsY29tZQ==",
                    "sequence_number": "0"
                },
                {
                    "partition_key": "shardId_0000000000",
                    "data": "dXNpbmc=",
                    "sequence_number": "1"
                },
                {
                    "partition_key": "shardId_0000000000",
                    "data": "RnVuY3Rpb25TdGFnZQ==",
                    "sequence_number": "2"
                },
                {
                    "partition_key": "shardId_0000000000",
                    "data": "c2VydmljZQ==",
                    "sequence_number": "3"
                }
            ],
            "millis_behind_latest": ""
        },
        "Tag": "latest",
        "StreamName": "dis-swtest"
    }
    表3 参数说明

    参数

    类型

    示例值

    描述

    ShardID

    String

    shardId-0000000000

    数据下载分区的ID

    next_partition_cursor

    String

    参考示例

    下一个分区的游标

    Records

    Map

    参考示例

    存储在DIS通道中的数据单元

    partition_key

    String

    参考示例

    分区键

    data

    String

    参考示例

    数据块,由数据生产者添加到数据通道

    sequence_number

    Int

    参考示例

    每个记录的唯一标识符,由DIS服务自动分配

    Tag

    String

    latest

    通道的标签

    StreamName

    String

    dis-swtest

    通道名称

  • TIMER示例事件
    {
        "version": "v1.0",
        "time": "2018-06-01T08:30:00+08:00",
        "trigger_type": "TIMER",
        "trigger_name": "Timer_001",
        "user_event": "User Event"
    }
    表4 参数说明

    参数

    类型

    示例值

    描述

    version

    String

    V1.0

    事件协议的版本

    time

    String

    2018-06-01T08:30:00+08:00

    事件产生的时间

    trigger_type

    String

    TIMER

    触发器的类型

    trigger_name

    String

    Timer_001

    触发器的名字

    user_event

    String

    User Event

    在创建触发器时配置的附加信息

  • LTS示例事件
    {
        "lts": {
            "data": "ICB7CiAgICAibG9ncyI6W3sKICAgICAgICAgIm1lc3NhZ2UiOiIyMDE4LTA4LTA4LzA4OjA4OjA4IFtXUk5dIFt0ZXN0LmdvOjA4XVRoaXMgaXMgYSB0ZXN0IG1lc3NhZ2UuIiwKICAgICAgICAgInRpbWUiOjE1MzAwMDk2NTMwNTksCiAgICAgICAgICJob3N0X25hbWUiOiJlY3MtdGVzdCIsCiAgICAgICAgICJpcCI6IjE5Mi4xNjguMS4xIiwKICAgICAgICAgInBhdGgiOiJ2YXIvbG9nL3Rlc3QubG9nIiwKICAgICAgICAgImxvZ191aWQiOiI2NjNkNjkzMC03OTJkLTExZTgtOGIwOC0yODZlZDQ4OGNlNzAiLAogICAgICAgICAibGluZV9ubyI6MQogICAgIH1dLAogICAgIm93bmVyIjogIjYyODBlMTcwYmQ5MzRmNjBhNGQ4NTFjZjVjYTA1MTI5IiwKICAgICJsb2dfZ3JvdXBfaWQiOiAiOTdhOWQyODQtNDQ0OC0xMWU4LThmYTQtMjg2ZWQ0ODhjZTcwIiwKICAgICJsb2dfdG9waWNfaWQiOiAiMWE5Njc1YTctNzg0ZC0xMWU4LTlmNzAtMjg2ZWQ0ODhjZTcwIgogfQ=="
        }
    }
    表5 Event中涉及的参数解释

    参数

    类型

    示例值

    描述

    data

    Sting

    参考示例

    Base64编码后的数据

  • CTS 示例事件
    {
        "cts": {
            "time": "2018/06/26 08:54:07 GMT+08:00",
            "user": {
                "name": "userName",
                "id": "5b726c4fbfd84821ba866bafaaf56aax",
                "domain": {
                    "name": "domainName",
                    "id": "b2b3853af40448fcb9e40dxj89505ba"
                }
            },
            "request": {},
            "response": {},
            "code": 204,
            "service_type": "vpc",
            "resource_type": "VPC",
            "resource_name": "workflow-2be1",
            "resource_id": "urn:fgs:{region}:2d1d891d93054bbaa69b9e866c0971ac:graph:workflow-2be1",
            "trace_name": "deleteGraph",
            "trace_type": "ConsoleAction",
            "record_time": "2018/06/26 08:54:07 GMT+08:00",
            "trace_id": "69be64a7-0233-11e8-82e4-e5d37911193e",
            "trace_status": "normal"
        }
    }
    表6 参数说明

    参数

    类型

    示例值

    描述

    User

    Map

    参考示例

    本次请求的发起用户信息

    Request

    Map

    参考示例

    事件请求内容

    Response

    Map

    参考示例

    事件响应内容

    Code

    Int

    204

    事件响应码,例如200、400

    service_type

    String

    vpc

    发送方的简写,比如vpc,ecs等等

    resource_type

    String

    VPC

    发送方资源类型,比如vm,vpn等等

    resource_name

    String

    workflow-2be1

    资源名称,例如ecs服务中某个虚拟机的名称

    trace_name

    String

    deleteGraph

    事件名称,比如:startServer, shutDown等

    trace_type

    String

    ConsoleAction

    事件发生源头类型,例如ApiCall

    record_time

    string

    2018/06/26 08:54:07 GMT+08:00

    cts服务接受到这条trace的时间

    trace_id

    String

    69be64a7-0233-11e8-82e4-e5d37911193e

    事件的唯一标识符

    trace_status

    String

    normal

    事件的状态

  • DDS示例事件
    {
        "records": [
            {
                "event_source": "dds",
                "event_name": "insert",
                "region": "{region}",
                "event_version": "1.0",
                "dds": {
                    "size_bytes": "100",
                    "token": "{\"_data\": \"825D8C2F4D0000001529295A100474039A3412A64BA89041DC952357FB4446645F696400645D8C2F8E5BECCB6CF5370D6A0004\"}",
                    "full_document": "{\"_id\": {\"$oid\": \"5d8c2f8e5beccb6cf5370d6a\"},\"name\": \"dds\",\"age\": {\"$numberDouble\": \"52.0\"}}",
                    "ns": "{\"db\": \"functiongraph\",\"coll\": \"person\"}"
                },
                "event_source_id": "e6065860-f7b8-4cca-80bd-24ef2a3bb748"
            }
        ]
    }
    表7 参数说明

    参数

    类型

    示例值

    描述

    region

    String

    cn-north-1

    DDS实例所在的地域

    event_version

    String

    1.0

    事件协议的版本

    event_source

    String

    dds

    事件的来源

    event_name

    String

    insert

    事件的名字

    size_bytes

    Int

    100

    消息的字节数

    token

    String

    参考示例

    Base64编码后的数据

    full_document

    String

    参考示例

    完整的文件信息

    ns

    String

    参考示例

    列名

    event_source_id

    e6065860-f7b8-4cca-80bd-24ef2a3bb748

    参考示例

    事件源唯一标识符

  • Kafka示例事件
    {
        "event_version": "v1.0",
        "event_time": 1576737962,
        "trigger_type": "KAFKA",
        "region": "{region}",
        "instance_id": "81335d56-b9fe-4679-ba95-7030949cc76b",
        "records": [
            {
                "messages": [
                    "kafka message1",
                    "kafka message2",
                    "kafka message3",
                    "kafka message4",
                    "kafka message5"
                ],
                "topic_id": "topic-test"
            }
        ]
    }
    表8 参数说明

    参数

    类型

    示例值

    描述

    event_version

    String

    v1.0

    事件协议的版本

    event_time

    String

    2018-01-09T07:50:50.028Z

    事件发生的时间

    trigger_type

    String

    KAFKA

    事件类型

    region

    String

    cn-north-1

    Kafka实例所在的地域

    instance_id

    String

    81335d56-b9fe-4679-ba95-7030949cc76b

    创建的Kafka实例的唯一标识符。

    messages

    String

    参考示例

    消息内容

    topic_id

    String

    topic-test

    消息的唯一标识符

  • GeminiDB示例事件
    {
        "records": [
            {
                "event_name": "\"insert\"",
                "event_version": "1.0",
                "event_source": "gemini_mongo",
                "region": "{region}",
                "gemini_mongo": {
                    "full_document": "{\"_id\": {\"$oid\":\"5f61de944778db5fcded3f87\"},\"zhangsan\": \"zhangsan\"}",
                    "ns": "{\"db\": \"zhangsan\",\"coll\": \"zhangsan\"}",
                    "size_bytes": "100",
                    "token": "{\"_data\": \"825F61DE940000000129295A1004A2D9AE61206C43A5AF47CAF7C5C00C5946645F696400645F61DE944778DB5FCDED3F870004\"}"
                },
                "event_source_id": "51153d19-2b7d-402c-9a79-757163258a36"
            }
        ],
        "vernier": "{\"_data\": \"825F61DE940000000129295A1004A2D9AE61206C43A5AF47CAF7C5C00C5946645F696400645F61DE944778DB5FCDED3F870004\"}"
    }
    表9 参数说明

    参数

    类型

    示例值

    描述

    region

    String

    cn-north-1

    GeminiDB实例所在的地域

    event_source

    String

    gemini_mongo

    事件的来源

    event_version

    String

    1.0

    事件协议的版本

    full_document

    String

    参考示例

    完整的文件信息

    size_bytes

    Int

    100

    消息的字节数

    token

    String

    参考示例

    Base64编码后的数据

    vernier

    String

    参考示例

    游标

  • RabbitMQ示例事件
    {
        "event_version": "v1.0",
        "event_time": 1576737962,
        "trigger_type": "RABBITMQ",
        "region": "{region}",
        "records": [
            {
                "messages": [
                    "rabbitmq message1",
                    "rabbitmq message2",
                    "rabbitmq message3",
                    "rabbitmq message4",
                    "rabbitmq message5"
                ],
                "instance_id": "81335d56-b9fe-4679-ba95-7030949cc76b",
                "exchange": "exchange-test"
            }
        ]
    }
    表10 参数说明

    参数

    类型

    示例值

    描述

    event_version

    String

    v1.0

    事件协议的版本

    Region

    String

    cn-north-1

    RabbitMQ实例所在的地域

    instance_id

    String

    81335d56-b9fe-4679-ba95-7030949cc76b

    创建的RabbitMQ实例的唯一标识符。

  • EG示例事件

    RocketMQ自定义事件源

    {
        "datacontenttype": "application/json",
        "data": {
            "context": "yyyyy"
        },
        "subject": "ROCKETMQ:region:domainId/projectId:ROCKETMQ:eventSourceName",
        "specversion": "1.0",
        "id": "016d5bd3-6231-4e9e-86ef-e451a070d598",
        "source": "eventSourceName",
        "time": "2023-04-07T11:51:10Z",
        "type": "ROCKETMQ:CloudTrace:RocketmqCall"
    }
    OBS应用事件源
    {
        "channel_id":"b65779ed-d9d0-4a6c-b312-c767226964cf",
        "description":"",
        "name":"subscription-xeak",
        "sources":[
            {
                "id":null,
                "name":"HC.OBS.DWR",
                "detail":{
                    "bucket":"eventbucket",
                    "objectKeyEncode":true
                },
                "filter":{
                    "source":[
                        {
                            "op":"StringIn",
                            "values":[
                                "HC.OBS.DWR"
                            ]
                        }
                    ],
                    "type":[
                        {
                            "op":"StringIn",
                            "values":[
                                "OBS:DWR:ObjectCreated:PUT",
                                "OBS:DWR:ObjectCreated:POST"
                            ]
                        }
                    ],
                    "subject":{
                        "and":[
                            {
                                "op":"StringStartsWith",
                                "values":[
                                    "/ddd"
                                ]
                            }
                        ]
                    },
                    "data":{
                        "obs":{
                            "bucket":{
                                "name":[
                                    {
                                        "op":"StringIn",
                                        "values":[
                                            "output-your"
                                        ]
                                    }
                                ]
                            }
                        }
                    }
                },
                "provider_type":"OFFICIAL"
            }
        ],
        "targets":[
            {
                "id":null,
                "name":"HC.FunctionGraph",
                "detail":{
                    "urn":"urn:fss:cn-north-7:c53626012ba84727b938ca8bf03108ef:function:A-nodejs-lqz:pylog:latest",
                    "agency_name":"EG_AGENCY"
                },
                "dead_letter_queue":null,
                "provider_type":"OFFICIAL",
                "transform":{
                    "type":"ORIGINAL",
                    "value":""
                }
            }
        ]
    }
    云服务事件源:
    {
        "specversion":"1.0",
        "id":"eaf3b6a6-d525-11ed-a4ca-1baaeb906770",
        "source":"HC.OBS",
        "type":"OBS:CloudTrace:Others",
        "datacontenttype":"application/json",
        "subject":"OBS:cn-north-5:1d60cc02b9814b9e8cab1ff36886cacb/a5b94f2084a14e3eb8273dd224b89d9a:OBJECT",
        "time":"2023-04-07T09:21:53.271Z",
        "data":{
            "code":"200",
            "source_ip":"10.62.9.176",
            "trace_type":"Others",
            "event_type":"data",
            "project_id":"a5b94f2084a14e3eb8273dd224b89d9a",
            "total_time":"138",
            "content_length":"6887848",
            "trace_id":"eaf3b6a6-d525-11ed-a4ca-1baaeb906770",
            "trace_name":"GET.OBJECT",
            "resource_type":"OBJECT",
            "trace_rating":"normal",
            "service_type":"OBS",
            "tracker_name":"obs-eg",
            "time":"1680859313271",
            "resource_name":"fangxin-sdk:SDK/nodejs-sdk.zip",
            "record_time":"1680859313271",
            "request_id":"000001875B05B4AB8411EF94DDE202C0",
            "user":{
                "domain":{
                    "id":"1d60cc02b9814b9e8cab1ff36886cacb",
                    "name":"hwstaff_pub_fcspaasw3"
                },
                "name":"devuser",
                "id":"0d8880584b0090271f7cc00857a7c7b9"
            }
        }
    }

    更多云服务事件源,请参见云服务事件源

    表11 参数说明

    参数

    类型

    示例值

    描述

    datacontenttype

    String

    application/json

    数据类型

    data

    Map

    见示例

    数据

    subject

    String

    见示例

    目标值

    specversion

    String

    1.0

    版本

    id

    String

    见示例

    唯一键值

    source

    String

    eventSourceName

    来源名称

    time

    String

    见示例

    发布订阅时间

    type

    String

    ROCKETMQ:CloudTrace:RocketmqCall

    订阅类型

support.huaweicloud.com/usermanual-functiongraph/functiongraph_01_0399.html