4
votes

We would like receive pubsub notifications on a topic, through our firebase cloud function with pubsub trigger (https://firebase.google.com/docs/functions/pubsub-events). However, https://firebase.google.com/docs/functions/pubsub-events does not indicate how to set up the pubsub subscription, only how to receive it once it comes to firebase.

pubsub subscription of type "push" seems to be what we want, so we don't need to pull. If we create a pubsub subscription of type "push", then we are supposed to specify a https endpoint, but as we understand it, the firebase pubsub trigger is a background function. Is there an associated https endpoint that we should specify for the pubsub subscription so the notification will correctly reach firebase and trigger the pubsub trigger in our firebase cloud functions?

Or do we need to create another push endpoint on app engine, for example, and then firebase pubsub cloud function will get triggered?

2

2 Answers

4
votes

You don't set up a subscription to make a pubsub topic work with Cloud Functions. The function will trigger when new messages are published to the topic. All you have to do is create the topic (use the gcloud command line to make this easy) and publish messages to it.

2
votes

Cloud Pub/Sub triggers can be fired at scheduled times using Google's Cloud Scheduler. The trigger can then fire your Firebase Cloud Function. You create the Pub/Sub topic from the Google Cloud Console.

exports.refresh = functions.runWith(runtimeExtended).pubsub.topic('cron-topic').onPublish((message, context) => {
  const messageBody = message.data ? Buffer.from(message.data, 'base64').toString() : null;
  console.log(context.timestamp + ' ' + context.eventId + ' : Refresh Function w payload ' + messageBody + ' fired.' );

  return // return your promisified/async function here, e.g. return admin.firestore().collection("foo").get();
});