pubsub

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package pubsub is the Cloud Pub/Sub emulation.

gRPC, not REST: the Go client speaks only gRPC, so a REST-only emulation would be unreachable from the client anyone actually uses. This is where the grpc dependency finally earns its place — the transport has carried an h2c dispatch point since the first milestone, answering 501, waiting for a service that exercises it.

Index

Constants

View Source
const EventPublish = "google.pubsub.topic.publish"

EventPublish is the event type a gen1 function is triggered by. Pub/Sub has only the one: a message arrived.

View Source
const MaxBodyBytes = 4 << 20

MaxBodyBytes caps a JSON request body.

These are metadata APIs: the largest thing they legitimately carry is a secret payload or a message, both far below this. Without a cap, one unauthenticated request with an endless body allocates until the emulator dies, which is a cheap way to take down everything else sharing the port.

View Source
const MessageType = "type.googleapis.com/google.pubsub.v1.PubsubMessage"

MessageType is the proto name gen1 puts in resource.type and in the payload.

View Source
const ServiceName = "pubsub.googleapis.com"

ServiceName is what gen1 reports in an event's resource.service.

Variables

This section is empty.

Functions

func SourceOf

func SourceOf(topic string) string

SourceOf identifies a topic as the source of an event.

Types

type Publisher

type Publisher struct {
	pubsubpb.UnimplementedPublisherServer
	// contains filtered or unexported fields
}

Publisher implements pubsubpb.PublisherServer.

func NewPublisher

func NewPublisher(s *Service) *Publisher

NewPublisher returns the publisher half of the service.

func (*Publisher) CreateTopic

func (p *Publisher) CreateTopic(ctx context.Context, t *pubsubpb.Topic) (*pubsubpb.Topic, error)

func (*Publisher) DeleteTopic

func (p *Publisher) DeleteTopic(ctx context.Context, req *pubsubpb.DeleteTopicRequest) (*emptypb.Empty, error)

func (*Publisher) GetTopic

func (p *Publisher) GetTopic(ctx context.Context, req *pubsubpb.GetTopicRequest) (*pubsubpb.Topic, error)

func (*Publisher) ListTopics

func (*Publisher) Publish

Publish fans a message out to every subscription on the topic.

func (*Publisher) UpdateTopic

func (p *Publisher) UpdateTopic(ctx context.Context, req *pubsubpb.UpdateTopicRequest) (*pubsubpb.Topic, error)

UpdateTopic applies the fields named by the update mask. Terraform reaches this on every change to an existing topic.

type REST

type REST struct {
	// contains filtered or unexported fields
}

REST serves the Pub/Sub JSON API over the same service the gRPC half uses.

It exists for Terraform: the Google provider speaks REST for every resource, so a gRPC-only Pub/Sub is invisible to it however complete it is.

func NewREST

func NewREST(s *Service) *REST

NewREST wires the JSON routes Terraform drives.

func (*REST) Matches

func (a *REST) Matches(method, escapedPath string) bool

Matches reports whether a route here claims the request. Cloud Functions mounts the same /v1/ prefix, so the two are told apart by route, not prefix.

func (*REST) ServeHTTP

func (a *REST) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service holds topics, subscriptions and undelivered messages.

func New

func New(kv store.Store, clk clock.Clock, bus *events.Bus) *Service

New wires a service.

type Subscriber

type Subscriber struct {
	pubsubpb.UnimplementedSubscriberServer
	// contains filtered or unexported fields
}

Subscriber implements pubsubpb.SubscriberServer.

func NewSubscriber

func NewSubscriber(s *Service) *Subscriber

NewSubscriber returns the subscriber half of the service.

func (*Subscriber) Acknowledge

func (b *Subscriber) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest) (*emptypb.Empty, error)

Acknowledge drops messages the subscriber has handled.

func (*Subscriber) CreateSubscription

func (b *Subscriber) CreateSubscription(ctx context.Context, sub *pubsubpb.Subscription) (*pubsubpb.Subscription, error)

func (*Subscriber) DeleteSubscription

func (b *Subscriber) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest) (*emptypb.Empty, error)

func (*Subscriber) GetSubscription

func (*Subscriber) ModifyAckDeadline

func (b *Subscriber) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest) (*emptypb.Empty, error)

ModifyAckDeadline with a deadline of zero is a nack: the message goes back on the queue at once. Any other deadline restarts the lease, which is how a subscriber still working on a message keeps it.

func (*Subscriber) Pull

Pull takes messages off a subscription's backlog.

returnImmediately is honoured rather than blocking: a pull with nothing to return answers empty. Blocking would need the wall clock, and StreamingPull is how a client waits for messages anyway.

func (*Subscriber) StreamingPull

func (b *Subscriber) StreamingPull(stream pubsubpb.Subscriber_StreamingPullServer) error

StreamingPull is how the Go client receives.

Subscriber.Receive opens a bidirectional stream and never calls Pull, so a service implementing only Pull is unreachable from the client anyone uses. The stream carries acks and nacks upward and messages downward at once.

func (*Subscriber) UpdateSubscription

UpdateSubscription applies the fields named by the update mask.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL