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.