sub

package
v0.0.0-...-1ea9000 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package sub creates PubSub subscriptions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, local bool, project string, topicName string, numGoRoutines int) (*pubsub.Subscription, error)

New returns a new *pubsub.Subscription.

project is the Google Cloud project that contains the PubSub topic.

topicName is the PubSub topic to listen to.

numGoRoutines is the number of Go routines we want to run.

Note that the returned subscription will have both sub.ReceiveSettings.MaxOutstandingMessages and sub.ReceiveSettings.NumGoroutines set, but they can be changed in the returned subscription.

The name of the returned subscription also takes 'local' into account, to avoid conflicting with subscriptions running in production. The topic and subscription are created if they don't already exist, which requires the "PubSub Admin" role.

func NewWithSubName

func NewWithSubName(ctx context.Context, local bool, project string, topicName string, subName string, numGoRoutines int) (*pubsub.Subscription, error)

NewWithSubName returns a new *pubsub.Subscription.

project is the Google Cloud project that contains the PubSub topic.

topicName is the PubSub topic to listen to.

subName is the name of the subscription.

numGoRoutines is the number of Go routines we want to run.

Note that the returned subscription will have both sub.ReceiveSettings.MaxOutstandingMessages and sub.ReceiveSettings.NumGoroutines set, but they can be changed in the returned subscription.

The topic and subscription are created if they don't already exist, which requires the "PubSub Admin" role.

func NewWithSubNameProvider

func NewWithSubNameProvider(ctx context.Context, local bool, project string, topicName string, subNameProvider SubNameProvider, numGoRoutines int) (*pubsub.Subscription, error)

NewWithSubNameProvider returns a new *pubsub.Subscription.

project is the Google Cloud project that contains the PubSub topic.

topicName is the PubSub topic to listen to.

subNameProvider generates a subscription name.

numGoRoutines is the number of Go routines we want to run.

Note that the returned subscription will have both sub.ReceiveSettings.MaxOutstandingMessages and sub.ReceiveSettings.NumGoroutines set, but they can be changed in the returned subscription.

The topic and subscription are created if they don't already exist, which requires the "PubSub Admin" role.

func NewWithSubNameProviderAndExpirationPolicy

func NewWithSubNameProviderAndExpirationPolicy(ctx context.Context, local bool, project string, topicName string, subNameProvider SubNameProvider, expirationPolicy *time.Duration, numGoRoutines int) (*pubsub.Subscription, error)

NewWithSubNameProviderAndExpirationPolicy returns a new *pubsub.Subscription.

project is the Google Cloud project that contains the PubSub topic.

topicName is the PubSub topic to listen to.

subNameProvider generates a subscription name.

expirationPolicy determines the inactivity period before the subscription is automatically deleted. The minimum allowed value is 1 day. Defaults to 31 days if nil.

numGoRoutines is the number of Go routines we want to run.

Note that the returned subscription will have both sub.ReceiveSettings.MaxOutstandingMessages and sub.ReceiveSettings.NumGoroutines set, but they can be changed in the returned subscription.

The topic and subscription are created if they don't already exist, which requires the "PubSub Admin" role.

Types

type BroadcastNameProvider

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

BroadcastNameProvider implements SubNameProvider. It prevents messages from being load-balanced across multiple subscribers by generating unique, per-machine subscription names (based on the machine's hostname). Use this provider when you want all machines to receive all messages in a topic.

In production, subscription names are appended a suffix to avoid conflicts with local subscriptions created during development.

Note that Kubernetes Deployments and ReplicaSets assign fresh hostnames to pods, so applications will leave behind one unused subscription per pod when restarted. Unused subscriptions will be garbage-collected after 31 days. See https://cloud.google.com/pubsub/docs/admin#pubsub_create_pull_subscription-go.

func NewBroadcastNameProvider

func NewBroadcastNameProvider(local bool, topicName string) BroadcastNameProvider

NewBroadcastNameProvider returns a new BroadcastNameProvider.

func (BroadcastNameProvider) SubName

func (b BroadcastNameProvider) SubName() (string, error)

SubName implements SubNameProvider.

type ConstNameProvider

type ConstNameProvider string

ConstNameProvider implements SubNameProvider that always returns the same subscription name.

func NewConstNameProvider

func NewConstNameProvider(subName string) ConstNameProvider

NewConstNameProvider returns a new ConstNameProvider.

func (ConstNameProvider) SubName

func (c ConstNameProvider) SubName() (string, error)

SubName implements SubNameProvider.

type RoundRobinNameProvider

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

RoundRobinNameProvider implements SubNameProvider. Use when running in production every instance uses the same subscription name so that they load-balance pulling items from the topic, and uses a different subscription name when running locally.

func NewRoundRobinNameProvider

func NewRoundRobinNameProvider(local bool, topicName string) RoundRobinNameProvider

NewRoundRobinNameProvider returns a new RoundRobinNameProvider.

func (RoundRobinNameProvider) SubName

func (r RoundRobinNameProvider) SubName() (string, error)

SubName implements SubNameProvider.

type SubNameProvider

type SubNameProvider interface {
	SubName() (string, error)
}

SubNameProvider is an interface for how a subscription name gets generated for a PubSub topic.

Jump to

Keyboard shortcuts

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