Building Google Cloud Platform Solutions
上QQ阅读APP看书,第一时间看更新

Cloud Pub/Sub functions

Cloud Pub/Sub is Google's managed event streaming service. Because serverless architectures tend to be heavily event-driven, triggering Cloud Functions from Pub/Sub is often a very powerful pattern. When creating a Pub/Sub trigger, developers specify the Pub/Sub topic to be used. Cloud Functions will generate a new push subscription for the specified topic in the form of gcf-<FUNCTION_NAME>-<TOPIC_NAME>. Note that the generated subscription will be automatically deleted upon deletion of the function.

Cloud Pub/Sub triggers deliver the following payload as the event body:

{
"eventId": "27819225098479",
"timestamp": "2018-01-27T18:11:24.836Z",
"eventType": "providers/cloud.pubsub/eventTypes/topic.publish",
"resource": "projects/<PROJECT_ID>/topics/<TOPIC_NAME>",
"data": {
"@type": "type.googleapis.com/google.pubsub.v1.PubsubMessage",
"attributes": {
"<KEY1>": "<VALUE1>",
"<KEY2>": "<VALUE2>"
},
"data": "YmFzZTY0IGVuY29kZWQgZGF0YQo="
}
}

Two points to note are that the data is delivered in base64 format, and that all attributes are available as the key-value attributes dictionary.