June 2018
Beginner to intermediate
394 pages
9h 2m
English
Cloud Pub/Sub is a message bus distributed globally. Using function.pubsub, we can trigger functions. Whenever a new Pub/Sub message is sent to a topic, cloud functions can trigger an event. You must define a Pub/Sub topic, and using the onPublish() function, we can handle the desired action:
exports.helloPubSub = functions.pubsub.topic('topic-name').onPublish(event => { // ...});
The payload of the Pub/Sub messages can be accessed through event.data as a message instance. Pub/Sub messages can be sent with attributes. Attributes are set with the publish command:
gcloud beta pubsub topics publish new_topic --attribute name=parinitha
And the previous attributes can be accessed like this:
const pubSubMessage = event
Read now
Unlock full access