Skip to content

Commit

Permalink
docs(pubsub): add emulator instructions to doc (#5652)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongalex committed Feb 15, 2022
1 parent 29c7f79 commit 435f757
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions pubsub/doc.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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"

0 comments on commit 435f757

Please sign in to comment.