Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Functions to only Ack Pub/Sub on success (Problem resolved by GCP)

An early version of Google Cloud Functions had a limitation with regards to retries when errors occurred. They have since provided enhancements that resolve this issue.


We are using a cloud function triggered by Pub/Sub to ensure delivery of an e-mail. Sometimes the e-mail service takes a long time to respond and our cloud function terminates before we get an error back. Since the message has already been acknowledged our e-mail gets lost.

The cloud function appears to be sending an ACK the Pub/Sub message automatically when we are called. Is there a way to delay the ACK until the successful completion of our code? Alternatively is there a way to catch timeouts and requeue the message for delivery? Something else we could try?

like image 286
Geoffrey Avatar asked May 12 '17 15:05

Geoffrey


People also ask

How does Pubsub work in GCP?

Google Cloud Pub/Sub provides messaging between applications. Cloud Pub/Sub is designed to provide reliable, many-to-many, asynchronous messaging between applications. Publisher applications can send messages to a "topic" and other applications can subscribe to that topic to receive the messages.

What is the core difference between cloud pub/sub and cloud tasks?

In this way, Pub/Sub supports implicit invocation: a publisher implicitly causes the subscribers to execute by publishing an event. By contrast, Cloud Tasks is aimed at explicit invocation where the publisher retains full control of execution.


2 Answers

I heard from Google support that they do not currently provide the means to delay the ACK when a cloud function is invoked by Pub/Sub. If you want to use cloud functions with Pub/Sub you need to handle the error case yourself. For example you could have your cloud function requeue a message for the retry with a retry count.

This would seem to make it unnecessarily difficult to guarantee execution with Pub/Sub and cloud functions.

like image 71
Geoffrey Avatar answered Oct 19 '22 08:10

Geoffrey


This is a problem because Functions ACKing a message on invoke, even if they crash, prevents the use of the new "dead-letter" feature.

Also, it goes against the docs. see note after this code sample: https://cloud.google.com/functions/docs/calling/pubsub#sample_code

like image 23
Nihil Avatar answered Oct 19 '22 09:10

Nihil