4

I have a Firebase Cloud Function that is triggered by a PubSub message. The function should either consume the message or wait to consume it at a later time.

Is there a way to return from this function without acknowledging the message, so that it will be re-delivered at a later time?

For example, can I return a Message from the cloud function? The docs seem to indicate this is possible, if I'm reading them right:

Returns non-null functions.CloudFunction containing non-null functions.pubsub.Message A Cloud Function which you can export.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
bcattle
  • 12,115
  • 6
  • 62
  • 82

1 Answers1

0

When PubSub trigger a function (Firebase or Cloud Function), if the function end correctly, the message is acknowledge. But if the function crash or raise an exception (in summary, an abnormal terminaison) the message not ack and resend immediately.

This retry loop is performed until the message is ack or the message expired (default and maximum TTL of 7 days, minimum is 10 minutes. You can customize the messageRetentionDuration in the subscription)

guillaume blaquiere
  • 66,369
  • 2
  • 47
  • 76
  • Is it really valid? I'm returning rejected promise and there is no other calls for firebase function with same message. Should it be specific error for rejection or any other special handling? – Michael Sotnikov Apr 16 '20 at 20:14
  • Can you share your code and show how you return your errors for noack? – guillaume blaquiere Apr 17 '20 at 07:34
  • Schematic code flow: https://pastebin.com/erme5D6p So I return rejected Promise with Error (name='OtherError', message=`') – Michael Sotnikov Apr 18 '20 at 10:28
  • hmm. Maybe I should re-throw error instead of returning rejected promise from `.catch()`? – Michael Sotnikov Apr 18 '20 at 10:38
  • does it have any language or firebase rationale why it will be any different? From my understanding ts/js - it's identical. – Michael Sotnikov Apr 18 '20 at 11:23
  • 2
    According to this issue: https://github.com/firebase/firebase-functions/issues/661, this reply is incorrect, and any execution would acknowledge message. Please note, that this is `firebase-functions`. Google Cloud Functions with their nodejs client library should work differently – Michael Sotnikov Apr 24 '20 at 07:46
  • Can you share a link to some documentation or quote an external source? Because it does not seem to be true (for firebase). – foobar443 Aug 14 '20 at 12:40