Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions functions/node8/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,30 @@ exports.makeUpperCase = (data, context) => {
});
};
// [END functions_firebase_reactive_node8]

// [START functions_async_pubsub_node8]
const PubSub = require('@google-cloud/pubsub');
let ps;

/**
* Triggered from a message on a Cloud Pub/Sub topic.
*
* @param {object} data The payload for the Pub/Sub message.
* @param {object} context The context object for the event.
*/
exports.helloPubSub = async (data, context) => {
ps = ps || new PubSub();
try {
const topicName = context.resource.name;
const topic = ps.topic(topicName);

// Get metadata for the topic
// This will call the Pub/Sub API
const data = await topic.getMetadata();
const metadata = data[0];
console.log(`Metadata: ${JSON.stringify(metadata)}`);
} catch(err) {
console.error(err);
}
};
// [END functions_async_pubsub_node8]
3 changes: 2 additions & 1 deletion functions/node8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"uuid": "^3.3.2"
},
"dependencies": {
"@google-cloud/firestore": "^0.18.0"
"@google-cloud/firestore": "^0.18.0",
"@google-cloud/pubsub": "^0.20.1"
}
}