Documentation
¶
Overview ¶
Package googlepubsub drives Google Cloud Pub/Sub over the Pub/Sub API.
It is the second family here with no broker address, and the first with two objects rather than one. There is nothing to dial: a topic is reached by naming a project and signing a request with a Google credential, and the endpoint is pubsub.googleapis.com for every project there is. So this driver's connection form declares no endpoint field at all, which is what model.DriverDescriptor.RequiresEndpoints reads to let a profile save with its Endpoints empty.
The vocabulary is where this family differs from the one before it. SQS has a queue and nothing else; Pub/Sub has a topic and a subscription, and the subscription is a real object - created, listed and deleted on its own, outliving nothing and nobody. A topic holds no messages: it fans a publish out to whatever subscriptions exist at that moment and discards it if none do. That single fact is what most of this package is arranged around, and what makes a topic with no subscription the fault worth alerting on.
What it can do with messages is bounded by there being only one read. Pull is the whole of it, and it is not a browse: a pulled message is held for the subscription's ack deadline, so a real consumer racing this app can miss one, and its delivery attempt counts towards the dead-letter policy's limit. The driver hands every message straight back and still declares the caveat, because handing it back is not instantaneous and the attempt does not come back down.
A dead-letter topic is an ordinary topic that a subscription's DeadLetterPolicy points at. That is DeadLetterTopology's shape rather than DeadLetterReader's - one object points at another - and the policy sits on the subscription, which is why each source names both the topic it came from and the subscription that gave up on it.
Index ¶
- Constants
- type Conn
- func (c *Conn) Capabilities() model.Capabilities
- func (c *Conn) Close() error
- func (c *Conn) CreateDestination(ctx context.Context, spec model.DestinationSpec) error
- func (c *Conn) CreateSnapshot(ctx context.Context, name, subscription string) error
- func (c *Conn) CreateSubscription(ctx context.Context, spec model.SubscriptionSpec) error
- func (c *Conn) CreateSubscriptionFrom(ctx context.Context, spec SubscriptionSpec) error
- func (c *Conn) CreateTopic(ctx context.Context, spec TopicSpec) error
- func (c *Conn) DeadLetterQueues(ctx context.Context, _ string) ([]*model.DeadLetterQueue, error)
- func (c *Conn) DestinationDetail(ctx context.Context, ref model.DestinationRef) (*model.Destination, error)
- func (c *Conn) Emulator() string
- func (c *Conn) Kind() model.MQKind
- func (c *Conn) ListDestinations(ctx context.Context, _ model.DestinationFilter) ([]*model.Destination, error)
- func (c *Conn) ListSnapshots(ctx context.Context) ([]*Snapshot, error)
- func (c *Conn) ListSubscriptions(ctx context.Context) ([]*model.Subscription, error)
- func (c *Conn) MessageByID(context.Context, string, string) (*model.MessageItem, error)
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Project() string
- func (c *Conn) Publish(ctx context.Context, request PublishRequest) (*PublishResult, error)
- func (c *Conn) QueryMessages(ctx context.Context, params model.MessageQueryParams) ([]*model.MessageItem, error)
- func (c *Conn) RemoveDestination(ctx context.Context, ref model.DestinationRef) error
- func (c *Conn) RemoveSnapshot(ctx context.Context, name string) error
- func (c *Conn) RemoveSubscription(ctx context.Context, ref model.SubscriptionRef) error
- func (c *Conn) ResetOffset(ctx context.Context, request model.ResetOffsetRequest) error
- func (c *Conn) SendMessage(ctx context.Context, topic, tags, keys, body string, delayLevel int) (string, error)
- func (c *Conn) SetSubscriptionPosition(ctx context.Context, request model.PositionRequest) error
- func (c *Conn) SubscriptionDetail(ctx context.Context, ref model.SubscriptionRef) (*model.Subscription, error)
- func (c *Conn) UpdateDestination(ctx context.Context, spec model.DestinationSpec) error
- func (c *Conn) UpdateSubscription(ctx context.Context, spec model.SubscriptionSpec) error
- func (c *Conn) UpdateSubscriptionFrom(ctx context.Context, spec SubscriptionSpec) error
- func (c *Conn) UpdateTopic(ctx context.Context, spec TopicSpec) error
- type Driver
- type PublishRequest
- type PublishResult
- type Snapshot
- type SubscriptionSpec
- type TopicSpec
Constants ¶
const ( AttrPath = "path" AttrRetentionSec = "retentionSec" AttrSubscriptionNames = "subscriptionNames" AttrKmsKey = "kmsKey" AttrSchema = "schema" AttrSchemaEncoding = "schemaEncoding" AttrStorageRegions = "storageRegions" AttrState = "state" // AttrLabelPrefix carries one label per attribute. Keys are the user's // own, so they are prefixed to keep them apart from the fields above. AttrLabelPrefix = "label." )
Attribute keys this driver puts on a destination.
A contract between this package and frontend/src/mq/googlepubsub/topics.ts, not part of the shared vocabulary.
const ( // OptionProjectID is what an endpoint field would be on any other family. // Every resource name begins with it, and it is also what the connection // row shows in its address column. OptionProjectID = "projectId" // OptionEmulatorHost is the host:port of a Pub/Sub emulator, which is the // same value the client library's own PUBSUB_EMULATOR_HOST carries. It is // named for the emulator rather than as a general endpoint override // because that is the only thing it can be: the real service has one // address for every project, so a connection that names a host is by // definition not talking to it. declare() reads that. OptionEmulatorHost = "emulatorHost" // OptionResourcePrefix narrows every listing to topics and subscriptions // whose short name starts with it. A project can hold thousands across // every team that uses it, and the API has no filter of its own. OptionResourcePrefix = "resourcePrefix" )
Option keys this driver stores in a connection profile.
A private contract between this package and the connection form in the renderer, the way every other family's are.
const ( PropDeliveryAttempt = "deliveryAttempt" PropOrderingKey = "orderingKey" PropSubscription = "subscription" // PropAttributePrefix carries one publisher-set attribute each. The keys // are the publisher's own, so they are prefixed to keep them apart from // the fields above. PropAttributePrefix = "attr." )
Message property keys this driver fills in. A contract between this package and frontend/src/mq/googlepubsub/messages.ts.
const ( SubAttrPath = "path" SubAttrTopic = "topic" SubAttrAckDeadlineSec = "ackDeadlineSec" SubAttrRetentionSec = "retentionSec" SubAttrRetainAcked = "retainAcked" SubAttrExpirationSec = "expirationTtlSec" SubAttrFilter = "filter" SubAttrOrdering = "messageOrdering" SubAttrExactlyOnce = "exactlyOnce" SubAttrDetached = "detached" SubAttrState = "state" SubAttrDelivery = "delivery" SubAttrPushEndpoint = "pushEndpoint" SubAttrDeadLetterTopic = "deadLetterTopic" SubAttrMaxAttempts = "maxDeliveryAttempts" SubAttrRetryMinSec = "retryMinBackoffSec" SubAttrRetryMaxSec = "retryMaxBackoffSec" // SubAttrLabelPrefix carries one label per attribute, the way a topic's do. SubAttrLabelPrefix = "label." )
Attribute keys this driver puts on a subscription.
A contract between this package and frontend/src/mq/googlepubsub/subscriptions.ts, not part of the shared vocabulary.
const ( DeliveryPull = "pull" DeliveryPush = "push" DeliveryBigQuery = "bigquery" DeliveryCloudStorage = "cloudStorage" DeliveryBigtable = "bigtable" )
How a subscription is delivered, which is four different objects wearing one name. Only a pull subscription is one this app can read messages from.
const ( // SecretCredentialsJSON holds the service account key itself, pasted in, // rather than a path to the file it came in. // // A path would be the smaller field and the worse one. It points at // something this app does not own: the key stays in plain text wherever it // was downloaded, the profile stops working the moment the file is moved, // and a profile exported to another machine takes a broken pointer with // it. Pasted, the key goes through the same encrypted store as every other // secret here and travels with the profile. The case a path exists for - // "the machine already holds the identity" - is Application Default // Credentials, which this driver uses whenever the field is left blank and // which reads GOOGLE_APPLICATION_CREDENTIALS among other things. SecretCredentialsJSON = "googleCredentialsJson" )
Secret keys this driver stores in a connection profile.
They are not model.SecretAccessKey and model.SecretSecretKey, and must never be: those two are reserved for RocketMQ's ACL, are written only through SetACL, and are filled from global settings for any profile that named no mechanism. A family reusing them would have its credentials cleared on save and RocketMQ's global pair stamped on at dial time.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is one live connection to one Google Cloud project's Pub/Sub.
"One connection" is an authenticated API client rather than a socket: the admin calls are unary RPCs that stand alone, so nothing is held open between them beyond the gRPC channel the client manages itself.
func (*Conn) Capabilities ¶
func (c *Conn) Capabilities() model.Capabilities
Capabilities is what this endpoint can do.
func (*Conn) Close ¶
Close releases what the connection holds. The registry closes on disconnect and on shutdown, so the second call has to be the one that does nothing.
func (*Conn) CreateDestination ¶
* CreateDestination declares a topic. * * Almost nothing is settable, so almost nothing is sent: a topic with no * retention keeps published messages only until every subscription has * acknowledged them, which is the default and what most topics want.
func (*Conn) CreateSnapshot ¶
CreateSnapshot takes a restore point from one subscription.
The snapshot belongs to the topic rather than to the subscription it came from: any subscription on the same topic can be sought to it, which is how a replay is set up for a second reader without disturbing the first.
func (*Conn) CreateSubscription ¶
* CreateSubscription declares a subscription on a topic. * * The topic is required and cannot change afterwards: a subscription reads * exactly one topic, chosen when it is made. Two of the settings are also * fixed at creation and are the reason this is not simply an update with a * name - message ordering and the filter can be set here and nowhere else, * and a filter is the only way to have a subscription receive part of a topic.
func (*Conn) CreateSubscriptionFrom ¶
func (c *Conn) CreateSubscriptionFrom(ctx context.Context, spec SubscriptionSpec) error
CreateSubscriptionFrom declares a subscription from a form submission.
func (*Conn) CreateTopic ¶
CreateTopic declares a topic from a form submission.
func (*Conn) DeadLetterQueues ¶
* DeadLetterQueues finds the topics subscriptions give up into. * * This is DeadLetterTopology's shape rather than DeadLetterReader's, and it * has to be: a dead-letter topic in Pub/Sub is an ordinary topic that some * subscription's DeadLetterPolicy points at. Nothing marks it, nothing is * named after a consumer group, and reading one afterwards means subscribing * to it like any other topic. * * Where it differs from the other family with this shape is which object holds * the policy. A RabbitMQ queue is declared with a dead-letter exchange, so a * source is a queue; here the policy belongs to the *subscription*, so one * topic read by three subscriptions can give up into three different places * for three different reasons. Every source therefore names both: the topic * the message came from, and the subscription that stopped trying. * * The consumer count is the figure worth reading. A dead-letter topic is a * topic, so it stores nothing - a dead letter published to one with no * subscription is discarded on the spot, and the messages a system gave up on * are exactly the ones nobody notices disappearing. Depth is unknown for the * same reason it is unknown everywhere else on this family: no number exists.
func (*Conn) DestinationDetail ¶
func (c *Conn) DestinationDetail(ctx context.Context, ref model.DestinationRef) (*model.Destination, error)
DestinationDetail reads one topic.
Not a walk of the listing: GetTopic takes one topic, so a project with a thousand of them should not answer for all of them to describe one.
func (*Conn) Emulator ¶
Emulator is the host this connection was pointed at, empty for the real service. It is what declare() narrows on, so the live tests can assert the narrowing rather than infer it.
func (*Conn) ListDestinations ¶
func (c *Conn) ListDestinations(ctx context.Context, _ model.DestinationFilter) ([]*model.Destination, error)
* ListDestinations enumerates the project's topics and counts what reads each. * * Two calls per board rather than one, and the second is the point of the * board. A Pub/Sub topic holds nothing: it fans a publish out to whatever * subscriptions exist at that moment and discards it if none do. So there is * no depth to show and the figure that matters is how many subscriptions are * attached - which ListTopics does not report and ListTopicSubscriptions * answers one topic at a time. * * The fan-out is bounded and the failures are tolerated per topic: a listing * that races a delete drops the row rather than failing the board, which is * the ordinary case in a project several teams share.
func (*Conn) ListSnapshots ¶
ListSnapshots is every restore point in the project.
func (*Conn) ListSubscriptions ¶
ListSubscriptions enumerates the project's subscriptions.
One call, unlike the topics board: everything a subscription reports is on the Subscription itself. What is not on it is the backlog, which is why the lag capability is degraded rather than answered here.
func (*Conn) MessageByID ¶
* MessageByID is not offered. Pub/Sub has no call that takes a message id: an * id is assigned on publish and echoed on delivery, and the only way to reach * a message is to be handed it. The capability is not declared, so nothing in * the UI reaches this.
func (*Conn) Ping ¶
Ping asks for one topic.
There is no health endpoint to call and nothing that answers unauthenticated, so the cheapest question that proves the credential still reaches the project is a listing stopped at the first row. A project with no topics answers it empty, which is a healthy connection and not an error.
func (*Conn) Project ¶
Project is which project this connection reads. The connection row shows it where every other family shows an address, because it is the only thing on this form that says where the topics are.
func (*Conn) Publish ¶
func (c *Conn) Publish(ctx context.Context, request PublishRequest) (*PublishResult, error)
* Publish sends one body, or the same body several times. * * The one thing worth knowing before pressing the button is where the message * goes, which is not "the topic". A topic stores nothing: the publish is fanned * out to whatever subscriptions exist at that instant and discarded if none * do, and the service reports success either way. So a send to a topic nothing * subscribes to is accepted, acknowledged and thrown away - which is why the * topics board marks that state and this call reports how many subscriptions * were attached when it ran.
func (*Conn) QueryMessages ¶
func (c *Conn) QueryMessages(ctx context.Context, params model.MessageQueryParams) ([]*model.MessageItem, error)
* QueryMessages reads what a subscription is holding, and hands it straight * back. * * Two things about it are worth reading twice. * * The first is what it reads. Every other family browses a destination; here * the topic holds nothing, so this browses a *subscription* - params.Topic * carries a subscription name, and the messages page offers subscriptions * rather than topics for exactly that reason. Two subscriptions on one topic * hold different messages, and there is no third place with all of them. * * The second is that this is not a browse, and the capability carries a caveat * saying so. Pull is the only read Pub/Sub has and it is the same call a * consumer makes: what it returns is held away from every other reader for the * subscription's ack deadline, and its delivery attempt goes up - which counts * towards the dead-letter policy's limit. So a page of messages read here is a * page a consumer running at the same moment did not get, and a message read * enough times ends up in the dead-letter topic with nothing having failed. * * What the driver can do is shorten the window and it does: every message is * handed back with a deadline of zero as soon as the batch is assembled, so * they are available again in about as long as the request takes. It cannot * close the window, and it cannot undo the delivery attempt. Hence the caveat * rather than a silent best effort. * * Filtering is left to the caller for the same reason the read is destructive: * a subscription's filter is fixed at creation and there is no per-request * selector of any kind, so narrowing would mean pulling everything and * discarding most of it - which would hide far more messages, for far longer, * than the page showed.
func (*Conn) RemoveDestination ¶
* RemoveDestination deletes a topic. * * What it does not delete is the subscriptions on it. They survive, keep * whatever they had not delivered, and report their topic as _deleted-topic_ * from then on - which is a subscription that can never receive another * message and goes on being billed for what it holds. The subscriptions board * is where those show up; this call does not clean them up, because deleting * somebody else's subscription is not what "delete this topic" asked for.
func (*Conn) RemoveSnapshot ¶
RemoveSnapshot deletes a restore point.
Worth doing rather than waiting for the expiry: while it exists the topic keeps every message the snapshot could restore, so an abandoned snapshot is storage nobody is paying attention to.
func (*Conn) RemoveSubscription ¶
RemoveSubscription deletes a subscription and everything it was holding.
There is no undo. The messages it had not acknowledged are gone with it - they were never the topic's to hand out again, which is the whole point of the split.
func (*Conn) ResetOffset ¶
* ResetOffset moves a subscription to a moment in time. * * ResetOffsetRequest is RocketMQ's shape and two of its four fields do not * apply: Topic is ignored because a subscription reads exactly one and it was * chosen at creation, and Force has no counterpart - Pub/Sub takes no account * of whether anything is attached, so there is no unforced variant to refuse.
func (*Conn) SendMessage ¶
func (c *Conn) SendMessage( ctx context.Context, topic, tags, keys, body string, delayLevel int, ) (string, error)
* SendMessage publishes through the canonical port. * * The port is RocketMQ's shape and three of its five arguments land * differently here, so each is handled deliberately rather than dropped: * * - tags is refused. A Pub/Sub message has a body and a table of named * attributes and nothing else, so a tag would be silently discarded and * the send reported as having carried it. * - keys carries the ordering key, which is the nearest thing Pub/Sub has to * what a RocketMQ key is for: the value a reader groups by. * - delayLevel is refused outright rather than converted. RocketMQ's levels * are an index into a broker-side table and SQS takes real seconds; * Pub/Sub has neither. A message is delivered as soon as there is a * subscription to deliver it to, and a console that accepted a delay would * report holding a message back that went out immediately.
func (*Conn) SetSubscriptionPosition ¶
* SetSubscriptionPosition moves a subscription to a named snapshot. * * PositionRequest's Position is an entry id on the family this port was * written for. Here it is a snapshot name, which is the same idea: the caller * is not describing a moment and asking the service to find it, but naming a * place it already holds.
func (*Conn) SubscriptionDetail ¶
func (c *Conn) SubscriptionDetail(ctx context.Context, ref model.SubscriptionRef) (*model.Subscription, error)
SubscriptionDetail reads one subscription.
func (*Conn) UpdateDestination ¶
* UpdateDestination changes a topic's settings. * * Only what the spec carries is sent, and the update mask is built from that: * UpdateTopic replaces exactly the fields the mask names and leaves the rest * alone, so an omitted key means "keep it" rather than "reset it". The one * consequence worth knowing is that labels are replaced wholesale - a form * editing them has to send the complete set, because sending one label with * the mask removes the others. * * The emulator serves this call for retention and refuses it for labels, * answering INVALID_ARGUMENT and saying labels is not a known Topic field. * That is the emulator rather than the API, and the live test pins it so the * gap is recorded rather than discovered by a user.
func (*Conn) UpdateSubscription ¶
* UpdateSubscription changes what can be changed. * * The mask is built from what the spec carries, so an omitted setting keeps * its value rather than being reset. Four things are refused rather than sent: * the topic, the filter, message ordering and the name are all fixed at * creation, and the service's own refusals name proto fields the form does not * draw.
func (*Conn) UpdateSubscriptionFrom ¶
func (c *Conn) UpdateSubscriptionFrom(ctx context.Context, spec SubscriptionSpec) error
UpdateSubscriptionFrom changes what a subscription lets be changed.
type Driver ¶
type Driver struct{}
Driver is the Google Cloud Pub/Sub family.
func (*Driver) Descriptor ¶
func (d *Driver) Descriptor() model.DriverDescriptor
Descriptor is the connection form and the family's best-case capabilities.
No endpoint field and no default port, both deliberately. There is no address a user could type and no port anything listens on: the client resolves pubsub.googleapis.com over HTTPS for every project. DriverDescriptor.RequiresEndpoints reads the absence of the field, and the connection service then lets the profile save with an empty Endpoints.
type PublishRequest ¶
type PublishRequest struct {
Topic string
Body string
// Count sends the same body more than once, for filling a subscription to
// watch a consumer work through it.
Count int
// Attributes are the publisher's own, sent as Pub/Sub message attributes.
// They are also the only thing a subscription filter can select on, so a
// send meant for a filtered subscription has to set them.
Attributes map[string]string
// OrderingKey groups messages that must be delivered in order relative to
// each other. It only has an effect on a subscription created with message
// ordering on; elsewhere it is carried and ignored.
OrderingKey string
}
PublishRequest is a send in Pub/Sub's own vocabulary.
Deliberately not MessagePublisher's shape. That one takes a topic, tags, keys and a delay level - RocketMQ's vocabulary, of which a Pub/Sub message has only the topic. There is no tag and no delay anywhere in the service: what a message carries beside its body is a table of string attributes, and what decides its ordering is a key rather than a queue.
type PublishResult ¶
type PublishResult struct {
// Sent is how many the service accepted.
Sent int
// MessageID is the id of the first message, so a page can name what it
// just produced. It addresses nothing: no call takes a message id.
MessageID string
}
PublishResult is what the send did.
type Snapshot ¶
type Snapshot struct {
Name string
// Topic is what the subscription it was taken from reads. A snapshot can
// only be sought to from a subscription on the same topic.
Topic string
// ExpiresAt is when the service will delete it, in epoch milliseconds.
ExpiresAt int64
Labels map[string]string
}
Snapshot is a restore point taken from one subscription.
It is not a copy of the messages: it is that subscription's acknowledgement state at a moment, and the topic goes on holding what it needs to honour it. Which is why one has an expiry - seven days from creation - and why leaving them lying around costs storage on the topic rather than on the snapshot.
type SubscriptionSpec ¶
type SubscriptionSpec struct {
Name string
// Topic is required on a create and ignored on an update: a subscription
// reads exactly one topic, chosen when it is made.
Topic string
// AckDeadlineSec is how long a delivered message is held before Pub/Sub
// offers it again. Zero leaves it alone, which on a create takes the
// service's default of ten seconds.
AckDeadlineSec int
// RetentionSec is how long an unacknowledged message is kept. Zero leaves
// it alone; the service's default is seven days.
RetentionSec int
// RetainAcked keeps acknowledged messages inside the retention window, so
// a seek can go back past them. Without it a seek can only skip forward.
RetainAcked bool
// ExactlyOnce turns on the stronger delivery guarantee, which also makes
// the acknowledgement itself something that can fail and be retried.
ExactlyOnce bool
// Filter is a Pub/Sub filter expression over message attributes. Set at
// creation and never afterwards: the service refuses the update, and so
// does the emulator with a message naming the emulator.
Filter string
// Ordering delivers messages with the same ordering key in order. Also
// fixed at creation.
Ordering bool
// PushEndpoint makes this a push subscription, which Pub/Sub POSTs to
// rather than holding for a reader. Empty is an ordinary pull one.
PushEndpoint string
// DeadLetterTopic is another topic's name; the driver resolves its path.
// Empty removes the policy on an update, which is the only way to.
DeadLetterTopic string
MaxAttempts int
// RetryMinBackoffSec and RetryMaxBackoffSec are sent together or not at
// all: the service refuses a policy carrying one of them.
RetryMinBackoffSec int
RetryMaxBackoffSec int
// Labels are set at creation only. The emulator refuses them in an update
// mask, which the real API accepts - and a form offering an edit that
// fails against the reference environment is worse than one that does not.
Labels map[string]string
}
* SubscriptionSpec is a subscription as the subscription form collects it. * * Deliberately not ConsumerGroupConfig's shape. That one takes a cluster, a * broker address, a consume mode, a retry count and a list of topics - * RocketMQ's vocabulary, of which a Pub/Sub subscription has exactly one * topic and nothing else. What it has instead is the whole of the delivery * configuration, because on this family that belongs to the subscription * rather than to the topic it reads. * * Four fields are fixed at creation and are why this is not simply an update * with a name: the topic, the filter, message ordering and the name itself.
type TopicSpec ¶
type TopicSpec struct {
Name string
// RetentionSec keeps published messages available for a subscription to
// seek back into. Zero means "leave it alone", which on an edit keeps
// whatever is stored and on a create takes the service's default - not
// retained beyond what every subscription still owes.
RetentionSec int
// Labels replace the topic's whole set rather than merging into it, which
// is the API's own behaviour: the update mask names the field, not one
// key. Nil leaves them alone; an empty map removes them all.
Labels map[string]string
}
* TopicSpec is a topic as the topic form collects it. * * Deliberately not TopicService.Create's shape. That one takes a broker * address, a read queue count, a write queue count and a permission string - * RocketMQ's vocabulary, of which a Pub/Sub topic has none. What it has * instead is almost nothing, and that is worth writing down rather than * hiding: everything about delivery belongs to the subscription, so a topic is * a name, an optional retention, and labels.