nodejs-pubsub icon indicating copy to clipboard operation
nodejs-pubsub copied to clipboard

Split from 1425: I also have a few other questions, if someone can help me will really appreciate it

Open feywind opened this issue 3 years ago • 1 comments

I also have a few other questions, if someone can help me will really appreciate it:

I have been following this guide to publish to a topic and then handle the topic once the cloud function receives it: https://firebase.google.com/docs/functions/pubsub-events

This is how the function that gets triggered when the topic is published is defined:

functions.pubsub.topic('topic-name').onPublish((message) => { // ... });

And this is how we publish to a topic:

const topic = pubsub.topic(req.body.topic);

const messageObject = { data: { message: req.body.message, }, }; const messageBuffer = Buffer.from(JSON.stringify(messageObject), 'utf8');

// Publishes a message try { await topic.publish(messageBuffer); res.status(200).send('Message published.'); } ....

My questions are:

  1. Once we publish a topic, is the ACK automatically handled by firebase cloud functions or is that something we need to implement? And when is it acknowledged? I read that when the incoming function (the one that is triggered when the topic is published) is called, it's acknowledged? "Unless an exception is thrown and automatic retrying is enabled, Cloud Functions acks incoming Pub/Sub messages internally upon function completion."
  2. We just want to publish the topic and forget the message and not really wait for it to finish. So in this case, can we skip await before the "topic.publish(messageBuffer)" or do we always have to await on the topic.publish?

Originally posted by @minuhariharan in https://github.com/googleapis/nodejs-pubsub/issues/1425#issuecomment-1015975436

feywind avatar Mar 24 '22 19:03 feywind

We just want to publish the topic and forget the message and not really wait for it to finish. So in this case, can we skip await before the "topic.publish(messageBuffer)" or do we always have to await on the topic.publish?

This part I can answer, at least. You should be able to publish and forget, as long as you don't want the message ID.

feywind avatar Aug 16 '22 19:08 feywind

Closing for inactivity.

feywind avatar Apr 11 '23 16:04 feywind