diff --git a/pubsub/doc.go b/pubsub/doc.go index a86fc3d4a594..2b081bfb01c9 100644 --- a/pubsub/doc.go +++ b/pubsub/doc.go @@ -63,8 +63,8 @@ Subsciptions may be created like so: Messages are then consumed from a subscription via callback. err := sub.Receive(context.Background(), func(ctx context.Context, m *Message) { - log.Printf("Got message: %s", m.Data) - m.Ack() + log.Printf("Got message: %s", m.Data) + m.Ack() }) if err != nil { // Handle error. @@ -136,5 +136,26 @@ Slow Message Processing For use cases where message processing exceeds 30 minutes, we recommend using the base client in a pull model, since long-lived streams are periodically killed by firewalls. See the example at https://godoc.org/cloud.google.com/go/pubsub/apiv1#example-SubscriberClient-Pull-LengthyClientProcessing + +Emulator + +To use an emulator with this library, you can set the PUBSUB_EMULATOR_HOST +environment variable to the address at which your emulator is running. This will +send requests to that address instead of to Cloud Pub/Sub. You can then create +and use a client as usual: + + // Set PUBSUB_EMULATOR_HOST environment variable. + err := os.Setenv("PUBSUB_EMULATOR_HOST", "localhost:9000") + if err != nil { + // TODO: Handle error. + } + // Create client as usual. + client, err := pubsub.NewClient(ctx, "my-project-id") + if err != nil { + // TODO: Handle error. + } + defer client.Close() + + */ package pubsub // import "cloud.google.com/go/pubsub"