Reputation: 3301
So we can set up the Cloud Function to listen to one topic, like the graph showed here.
Would it be possible that we have one function listen to multiple topics?
For example, I could have a function email me the errors. And if I can have this function to listen to multiple topics (each topic will be reporting one particular process error), I don't have to have one function for each one topic which doing the same thing, email me the error message.
Thanks!
Upvotes: 5
Views: 2789
Reputation: 599906
You will need a separate trigger for each PubSub topic, but can easily then call a simple higher-order function to do all the work.
exports.helloPubSub = functions.pubsub.topic('topic-name').onPublish((message) => {
pubsubHandler('topic-name', message)
});
exports.worldPubSub = functions.pubsub.topic('topic-name2').onPublish((message) => {
pubsubHandler('topic-name2', message)
});
function pubsubHandler(topic, message) {
...
}
Upvotes: 3