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
- func SourceOf(topic string) string
- type Publisher
- func (p *Publisher) CreateTopic(ctx context.Context, t *pubsubpb.Topic) (*pubsubpb.Topic, error)
- func (p *Publisher) DeleteTopic(ctx context.Context, req *pubsubpb.DeleteTopicRequest) (*emptypb.Empty, error)
- func (p *Publisher) GetTopic(ctx context.Context, req *pubsubpb.GetTopicRequest) (*pubsubpb.Topic, error)
- func (p *Publisher) ListTopics(ctx context.Context, req *pubsubpb.ListTopicsRequest) (*pubsubpb.ListTopicsResponse, error)
- func (p *Publisher) Publish(ctx context.Context, req *pubsubpb.PublishRequest) (*pubsubpb.PublishResponse, error)
- func (p *Publisher) UpdateTopic(ctx context.Context, req *pubsubpb.UpdateTopicRequest) (*pubsubpb.Topic, error)
- type REST
- type Service
- type Subscriber
- func (b *Subscriber) Acknowledge(ctx context.Context, req *pubsubpb.AcknowledgeRequest) (*emptypb.Empty, error)
- func (b *Subscriber) CreateSubscription(ctx context.Context, sub *pubsubpb.Subscription) (*pubsubpb.Subscription, error)
- func (b *Subscriber) DeleteSubscription(ctx context.Context, req *pubsubpb.DeleteSubscriptionRequest) (*emptypb.Empty, error)
- func (b *Subscriber) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest) (*pubsubpb.Subscription, error)
- func (b *Subscriber) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest) (*pubsubpb.ListSubscriptionsResponse, error)
- func (b *Subscriber) ModifyAckDeadline(ctx context.Context, req *pubsubpb.ModifyAckDeadlineRequest) (*emptypb.Empty, error)
- func (b *Subscriber) Pull(ctx context.Context, req *pubsubpb.PullRequest) (*pubsubpb.PullResponse, error)
- func (b *Subscriber) StreamingPull(stream pubsubpb.Subscriber_StreamingPullServer) error
- func (b *Subscriber) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest) (*pubsubpb.Subscription, error)
Constants ¶
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.
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.
const MessageType = "type.googleapis.com/google.pubsub.v1.PubsubMessage"
MessageType is the proto name gen1 puts in resource.type and in the payload.
const ServiceName = "pubsub.googleapis.com"
ServiceName is what gen1 reports in an event's resource.service.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Publisher ¶
type Publisher struct {
pubsubpb.UnimplementedPublisherServer
// contains filtered or unexported fields
}
Publisher implements pubsubpb.PublisherServer.
func NewPublisher ¶
NewPublisher returns the publisher half of the service.
func (*Publisher) CreateTopic ¶
func (*Publisher) DeleteTopic ¶
func (*Publisher) ListTopics ¶
func (p *Publisher) ListTopics(ctx context.Context, req *pubsubpb.ListTopicsRequest) (*pubsubpb.ListTopicsResponse, error)
func (*Publisher) Publish ¶
func (p *Publisher) Publish(ctx context.Context, req *pubsubpb.PublishRequest) (*pubsubpb.PublishResponse, error)
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.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service holds topics, subscriptions and undelivered messages.
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 (b *Subscriber) GetSubscription(ctx context.Context, req *pubsubpb.GetSubscriptionRequest) (*pubsubpb.Subscription, error)
func (*Subscriber) ListSubscriptions ¶
func (b *Subscriber) ListSubscriptions(ctx context.Context, req *pubsubpb.ListSubscriptionsRequest) (*pubsubpb.ListSubscriptionsResponse, error)
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 ¶
func (b *Subscriber) Pull(ctx context.Context, req *pubsubpb.PullRequest) (*pubsubpb.PullResponse, error)
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 ¶
func (b *Subscriber) UpdateSubscription(ctx context.Context, req *pubsubpb.UpdateSubscriptionRequest) (*pubsubpb.Subscription, error)
UpdateSubscription applies the fields named by the update mask.