Skip to content

Commit fe2ec56

Browse files
authored
docs(pubsub): add doc links to top level package doc (#11029)
* docs(pubsub): add doc links to top level package doc * revert changes to go.work.sum
1 parent 706ecb2 commit fe2ec56

1 file changed

Lines changed: 25 additions & 35 deletions

File tree

pubsub/doc.go

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,51 @@
1414

1515
/*
1616
Package pubsub provides an easy way to publish and receive Google Cloud Pub/Sub
17-
messages, hiding the details of the underlying server RPCs. Google Cloud
17+
messages, hiding the details of the underlying server RPCs.
1818
Pub/Sub is a many-to-many, asynchronous messaging system that decouples senders
1919
and receivers.
2020
21-
More information about Google Cloud Pub/Sub is available at
21+
More information about Pub/Sub is available at
2222
https://cloud.google.com/pubsub/docs
2323
2424
See https://godoc.org/cloud.google.com/go for authentication, timeouts,
2525
connection pooling and similar aspects of this package.
2626
2727
# Publishing
2828
29-
Google Cloud Pub/Sub messages are published to topics. Topics may be created
30-
using the pubsub package like so:
29+
Pub/Sub messages are published to topics. A [Topic] may be created
30+
using [Client.CreateTopic] like so:
3131
3232
topic, err := pubsubClient.CreateTopic(context.Background(), "topic-name")
3333
34-
Messages may then be published to a topic:
34+
Messages may then be published to a [Topic]:
3535
3636
res := topic.Publish(ctx, &pubsub.Message{Data: []byte("payload")})
3737
38-
Publish queues the message for publishing and returns immediately. When enough
38+
[Topic.Publish] queues the message for publishing and returns immediately. When enough
3939
messages have accumulated, or enough time has elapsed, the batch of messages is
4040
sent to the Pub/Sub service.
4141
42-
Publish returns a PublishResult, which behaves like a future: its Get method
42+
[Topic.Publish] returns a [PublishResult], which behaves like a future: its Get method
4343
blocks until the message has been sent to the service.
4444
45-
The first time you call Publish on a topic, goroutines are started in the
46-
background. To clean up these goroutines, call Stop:
45+
The first time you call [Topic.Publish] on a [Topic], goroutines are started in the
46+
background. To clean up these goroutines, call [Topic.Stop]:
4747
4848
topic.Stop()
4949
5050
# Receiving
5151
52-
To receive messages published to a topic, clients create subscriptions
53-
to the topic. There may be more than one subscription per topic; each message
54-
that is published to the topic will be delivered to all of its subscriptions.
52+
To receive messages published to a [Topic], clients create a [Subscription]
53+
for the topic. There may be more than one subscription per topic ; each message
54+
that is published to the topic will be delivered to all associated subscriptions.
5555
56-
Subscriptions may be created like so:
56+
A [Subscription] may be created like so:
5757
5858
sub, err := pubsubClient.CreateSubscription(context.Background(), "sub-name",
5959
pubsub.SubscriptionConfig{Topic: topic})
6060
61-
Messages are then consumed from a subscription via callback.
61+
Messages are then consumed from a [Subscription] via callback.
6262
6363
err := sub.Receive(context.Background(), func(ctx context.Context, m *Message) {
6464
log.Printf("Got message: %s", m.Data)
@@ -69,19 +69,19 @@ Messages are then consumed from a subscription via callback.
6969
}
7070
7171
The callback is invoked concurrently by multiple goroutines, maximizing
72-
throughput. To terminate a call to Receive, cancel its context.
72+
throughput. To terminate a call to [Subscription.Receive], cancel its context.
7373
74-
Once client code has processed the message, it must call Message.Ack or
75-
Message.Nack; otherwise the message will eventually be redelivered. Ack/Nack
76-
MUST be called within the Receive handler function, and not from a goroutine.
74+
Once client code has processed the [Message], it must call Message.Ack or
75+
Message.Nack; otherwise the Message will eventually be redelivered. Ack/Nack
76+
MUST be called within the [Subscription.Receive] handler function, and not from a goroutine.
7777
Otherwise, flow control (e.g. ReceiveSettings.MaxOutstandingMessages) will
7878
not be respected, and messages can get orphaned when cancelling Receive.
7979
8080
If the client cannot or doesn't want to process the message, it can call Message.Nack
8181
to speed redelivery. For more information and configuration options, see
82-
"Ack Deadlines" below.
82+
Ack Deadlines below.
8383
84-
Note: It is possible for Messages to be redelivered even if Message.Ack has
84+
Note: It is possible for a [Message] to be redelivered even if Message.Ack has
8585
been called. Client code must be robust to multiple deliveries of messages.
8686
8787
Note: This uses pubsub's streaming pull feature. This feature has properties that
@@ -91,7 +91,7 @@ pull method.
9191
9292
# Streams Management
9393
94-
The number of StreamingPull connections can be configured by setting sub.ReceiveSettings.NumGoroutines.
94+
The number of StreamingPull connections can be configured by setting NumGoroutines in [ReceiveSettings].
9595
The default value of 10 means the client library will maintain 10 StreamingPull connections.
9696
This is more than sufficient for most use cases, as StreamingPull connections can handle up to
9797
10 MB/s https://cloud.google.com/pubsub/quotas#resource_limits. In some cases, using too many streams
@@ -125,10 +125,8 @@ either:
125125
- The "MaxExtension" duration elapses from the time the message is fetched from
126126
the server. This defaults to 60m.
127127
128-
Ack deadlines are extended periodically by the client. The initial ack
129-
deadline given to messages is based on the subscription's AckDeadline property,
130-
which defaults to 10s. The period between extensions, as well as the
131-
length of the extension, automatically adjusts based on the time it takes the
128+
Ack deadlines are extended periodically by the client. The period between extensions,
129+
as well as the length of the extension, automatically adjusts based on the time it takes the
132130
subscriber application to ack messages (based on the 99th percentile of ack latency).
133131
By default, this extension period is capped at 10m, but this limit can be configured
134132
by the "MaxExtensionPeriod" setting. This has the effect that subscribers that process
@@ -144,15 +142,7 @@ library sends such an extension: the Pub/Sub server would wait the remaining
144142
2m55s before re-sending the messages out to other subscribers.
145143
146144
Please note that by default, the client library does not use the subscription's
147-
AckDeadline for the MaxExtension value. To enforce the subscription's AckDeadline,
148-
set MaxExtension to the subscription's AckDeadline:
149-
150-
cfg, err := sub.Config(ctx)
151-
if err != nil {
152-
// TODO: handle err
153-
}
154-
155-
sub.ReceiveSettings.MaxExtension = cfg.AckDeadline
145+
AckDeadline for the MaxExtension value.
156146
157147
# Slow Message Processing
158148
@@ -164,7 +154,7 @@ by firewalls. See the example at https://godoc.org/cloud.google.com/go/pubsub/ap
164154
165155
To use an emulator with this library, you can set the PUBSUB_EMULATOR_HOST
166156
environment variable to the address at which your emulator is running. This will
167-
send requests to that address instead of to Cloud Pub/Sub. You can then create
157+
send requests to that address instead of to Pub/Sub. You can then create
168158
and use a client as usual:
169159
170160
// Set PUBSUB_EMULATOR_HOST environment variable.

0 commit comments

Comments
 (0)