0

0

I encountered a problem at work. I am implementing purchase notifications for my company's game in Google Play Store. I bind a Google Cloud project which has a Pub/Sub topic and subscription with Google Play Console. I have completed the relevant settings on the Play and Cloud platforms and written a demo using the SDK methods to get notifications through Streaming Pull (https://pkg.go.dev/cloud.google.com/go/pubsub#hdr-Receiving). In my demo, I could get TestNotification, but the OneTimeProductNotification was very weird. For example, of the dozens of purchases made that day, this demo only received two or three messages, and most of the messages could not be pulled from the Subscription, but instead reported a StreamingPull error. I use the Ack method for all received messages, bind Cloud project with Play Console, and give Pub/Sub Topic the Admin permissions. image of error

go
package main

import (
    "cloud.google.com/go/pubsub"
    "context"
    "google.golang.org/api/option"
    "log"
)

func main() {
    ctx := context.Background()
    clientOpts := option.WithCredentialsFile("./cred.json")
    client, err := pubsub.NewClient(ctx, "****************", clientOpts)
    if err != nil {
        log.Fatal(err)
    }
    sub := client.Subscription("test-sub")
    handler := func(ctx context.Context, m *pubsub.Message) {
        log.Println(m)
        log.Println(string(m.Data))
        m.Ack()
    }
    err = sub.Receive(ctx, handler)
    if err != nil {
        log.Fatal(err)
    }
}

I hope to correctly receive all OneTimeProductNotification, any help would be greatly appreciated.

1 Answers1

0

The error rate for streaming pull is expected. See the documentation:

StreamingPull streams always close with a non-OK status. Unlike in unary RPCs, this status for StreamingPull is simply an indication that the stream is broken. The requests are not failing. Therefore, while the StreamingPull API might have a surprising 100% error rate, this behavior is by design.

There are several metrics to look at to determine why you may not be receiving messages:

  1. Are you sure the messages were published? Look at the topic/send_request_count metric for the topic to ensure the expected number of requests were sent.

  2. Is there a backlog of messages? Look at the subscription/oldest_unacked_message_age metric to see if there are messages that were published that were not delivered to your subscription. If there is no backlog, that means that either messages were not published or that messages were consumed and acknowledged. If they were published, but didn't get acknowledged by this subscriber, make sure you don't have another subscriber running that could have consumed and acknowledged them (maybe a forgotten process running in another terminal). If there is a backlog, that means messages are not being consumed by your subscriber. The simplicity of the subscriber code indicates it probably isn't an issue with the code itself.

You should also double check to ensure you don't have a filter set up on your subscription that could result in messages not being delivered to your subscriber.

Kamal Aboul-Hosn
  • 15,111
  • 1
  • 34
  • 46
  • I have read the documentation, and I have checked the points you mentioned. My Subscription has no Filters, and when I check the metrics, I found that the actual received messages were very few. Later I found another answer: (https://stackoverflow.com/questions/65029988/android-real-time-developer-notification-for-one-time-purchase-is-half-working) It seems that the Google Play's Android developer real-time notifications has problems itself. Now I give up using Pub/Sub. I plan to implement it by my self, instead of relying on the API provided by the platform. Anyway, thanks for your help! – Simon5ei May 23 '23 at 02:33