Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
feywind opened this issue Mar 24, 2022 · 2 comments
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. type: question Request for information or clarification. Not an issue.

Comments

@feywind
Copy link
Collaborator

feywind commented Mar 24, 2022

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 #1425 (comment)

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/nodejs-pubsub API. label Mar 24, 2022
@feywind feywind added the type: question Request for information or clarification. Not an issue. label Mar 24, 2022
@feywind
Copy link
Collaborator Author

feywind commented Aug 16, 2022

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
Copy link
Collaborator Author

feywind commented Apr 11, 2023

Closing for inactivity.

@feywind feywind closed this as completed Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/nodejs-pubsub API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

1 participant