I am trying to set up a toy to understand Google's Pub/Sub service Go client API. I have had no trouble with publishing and have a local emulator for the Google Scheduler service to build against, but I am having a lot of trouble getting subscriptions to work.
I am able get a subscription to work with messages received if I first create the topic using the Python example code. This is the python from[1]: ``` from google.cloud import pubsub_v1 publisher = pubsub_v1.PublisherClient() subscriber = pubsub_v1.SubscriberClient() topic_path = publisher.topic_path(project, topic) subscription_path = subscriber.subscription_path(project, subID) # Wrap the subscriber in a 'with' block to automatically call close() to # close the underlying gRPC channel when done. with subscriber: subscription = subscriber.create_subscription( request={"name": subscription_path, "topic": topic_path} ) ``` However, when I do what I understand to be the equivalent Go code, I am unable to receive any messages. This is what I take to be the equivalent Go code. ``` client, err := pubsub.NewClient(ctx, project) if err != nil { log.Fatalf("failed to create pubsub client: %v", err) } t, err := client.CreateTopic(ctx, topic) if err != nil { log.Fatalf("failed to create topic %q: %v", topic, err) } s, err := client.CreateSubscription(ctx, subID, pubsub.SubscriptionConfig{Topic: t}) if err != nil { log.Fatalf("failed to create subscription %q %q: %v", topic, subID, err) } ``` In both cases the message receiver code is as follows, though in the case where python sets up the topic, this is prefaced with `s := client.Subscription(subID)` in place of the Go code above. ``` err = s.Receive(ctx, func(ctx context.Context, m *pubsub.Message) { log.Printf("received: %#v", m) m.Ack() }) ``` The complete code of the working toy (requiring python to set it up) is here [2] and the non-working version is here [3]. thanks Dan [1] https://github.com/googleapis/python-pubsub/blob/b8352f91c63e0cb7d64c4d0e557651248cd301b5/samples/snippets/subscriber.py#L66-L89 [2]https://play.golang.org/p/0kXLN8H-rCG [3]https://play.golang.org/p/Fva4BYrtDXE -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/aa4b92bcd9138eb95ebe73cdb7483eea912649bf.camel%40kortschak.io.