Documentation
¶
Overview ¶
Package gcppubsub is the Google Cloud Pub/Sub broker of the pubsub package:
ps, err := pubsub.ForApp(app, gcppubsub.Driver())
Settings: PUBSUB_DRIVER=gcp, PUBSUB_GCP_PROJECT (the project's ID), and PUBSUB_GCP_CREATE=true to create missing topics and subscriptions (for development and the emulator; in production, create them with your infrastructure tools). Credentials come from Application Default Credentials; PUBSUB_EMULATOR_HOST selects the emulator.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker is a pub/sub broker on Google Cloud Pub/Sub. Topic and subscription IDs are the names with the prefix, with "%" and the characters Pub/Sub doesn't allow in IDs (such as ":") escaped as "%XX".
The client extends ack deadlines while a message is handled, up to the listener's ack timeout. A failed message is nacked: Pub/Sub delivers it again as the subscription's retry policy says (the listener's Backoff doesn't apply). Message.Attempt is set only for subscriptions with a dead-letter policy; without one, the listener's MaxAttempts can't apply.
func NewBroker ¶
NewBroker returns a broker using client, with IDs starting with prefix; with create, it creates missing topics and subscriptions. Closing the broker closes the client.
func (*Broker) Close ¶
Close implements pubsub.Broker: it stops the publishers and closes the client.
func (*Broker) Prepare ¶
Prepare implements pubsub.Broker. With create, it creates the subscription (and its topic) if it doesn't exist, with the ack deadline of the listener's ack timeout (10s to 600s) and a retry policy backing off from 10s to 600s; that needs the pubsub.subscriptions.get and .create and pubsub.topics.create permissions. Without create, it only checks the names: a missing subscription shows when the listener starts.
func (*Broker) Publish ¶
Publish implements pubsub.Broker. With create, a missing topic is created.
type Config ¶
type Config struct {
// Project is the Google Cloud project's ID. PUBSUB_GCP_PROJECT.
Project string `env:"PUBSUB_GCP_PROJECT"`
// Create creates missing topics and subscriptions. PUBSUB_GCP_CREATE,
// default false.
Create bool `env:"PUBSUB_GCP_CREATE" default:"false"`
}
Config is the broker's settings.