firebase / firebase-functions

Firebase SDK for Cloud Functions
https://firebase.google.com/docs/functions/
MIT License
1.01k stars 202 forks source link

onMessagePublished does not acknowledge messages from Google Play Billing #1571

Closed MileyHollenberg closed 1 month ago

MileyHollenberg commented 1 month ago

[REQUIRED] Version info

node: V20.11.1

firebase-functions: ^5.0.1

firebase-tools: 13.8.0

firebase-admin: ^12.0.1

[REQUIRED] Test case

Simply create a function with the following code

import { onMessagePublished } from "firebase-functions/v2/pubsub";
import { setGlobalOptions } from "firebase-functions/v2";
import * as admin from "firebase-admin";
import { getFirestore } from "firebase-admin/firestore";

setGlobalOptions({ region: "europe-west1" });
admin.initializeApp();
const db = getFirestore("database-id");

export const GPlayBilling = onMessagePublished("topic-name", async (event) => {
    const pubsubMessage = event.data.message.json;
    await db.collection("purchases").add(pubsubMessage);
    return true;
});

Create a pub-sub topic with these settings

firefox_fRLetxAUzM firefox_lvUnfV4mMa

And link it to an app in the Google Play Dashboard

firefox_OzAedUQLk0

[REQUIRED] Expected behavior

When the function finishes it should acknowledge the event in PubSub

[REQUIRED] Actual behavior

PubSub sees the message as un-acknowledged even though it doesn't seem to replay it afterwards (set to replay after 10 seconds up to 600 seconds delay)

firefox_9RFzhPFC0z firefox_YLS2Ve1TVC firefox_JzQ2TmRP6Q

Were you able to successfully deploy your functions?

Yes, the function gets called and the data gets stored in Firestore but the message simply isn't being acknowledged. I've looked if there is a function I need to call in order to acknowledge the message but everything points towards a successful function call automatically acknowledging the message.

google-oss-bot commented 1 month ago

I found a few problems with this issue:

MileyHollenberg commented 1 month ago

Ah never mind, I found the reason, the Firebase function created its own subscription and the one I was looking at was the one I made myself. For some reason the Firebase created one didn't show up in my list of subscriptions for a while. Just found it and deleted my manually created one. Now everything is working as expected including the messages being acknowledged properly :) (also the subscription created by Firebase was a Push rather than Pull setup which is also why the messages weren't getting re-played even though they were in the queue)