pubsub

package
v0.11.15 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultProjectIdEnvVar = "PUBSUB_GCLOUD_PROJECT_ID"
	DefaultEmulatorHost    = "localhost:8802"
	EmulatorHostEnvVar     = "PUBSUB_EMULATOR_HOST"
)

Variables

View Source
var DefaultRetryPolicy = pubsub.RetryPolicy{
	MinimumBackoff: time.Second,
	MaximumBackoff: 10 * time.Minute,
}

Functions

func DefaultProjectId

func DefaultProjectId() string

Types

type AuthenticationMethod added in v0.10.10

type AuthenticationMethod = pubsub.AuthenticationMethod

type Client

type Client interface {
	ClientCommon
	IsEmulator() bool
	CreateTopic(ctx context.Context, topicID string) (Topic, error)
	Subscription(id string) Subscription
	SubscriptionInProject(id, projectID string) Subscription
	Subscriptions(context.Context) SubscriptionIterator
	Topic(id string) Topic
	TopicInProject(id, projectID string) Topic
	Topics(context.Context) TopicIterator
}

func DefaultClient

func DefaultClient(promNamespace string) (Client, error)

func MustDefaultClient

func MustDefaultClient() Client

func NewClient

func NewClient(
	ctx context.Context,
	projectID string,
	promReg prometheus.Registerer,
	promNamespace string,
	promLabels prometheus.Labels,
	opts ...option.ClientOption,
) (Client, error)

type ClientCommon

type ClientCommon interface {
	Close() error
}

type FanoutMessageHandler

type FanoutMessageHandler func(context.Context, Message) RetriableError

func RouteBy

func RouteBy(classifier func(Message) string, handlers map[string]FanoutMessageHandler) FanoutMessageHandler

RouteBy uses a classifier function to chose exactly one handler to process a message. If no handler matches the classifier return, routing handler will return nil (no error).

type Message

type Message interface {
	MessageCommon
	RealMessage() *RealMessage
}

type MessageCommon

type MessageCommon interface {
	Ack()
	Nack()
}

type MessageHandler

type MessageHandler func(context.Context, Message)

func Fanout

func Fanout(handlers ...FanoutMessageHandler) MessageHandler

Fanout creates a composite handler that will call each of the given handlers concurrently, and ack the message if all of them either succeed or return non-retriable errors, or else nack the message if any returns a retriable error.

Fanout will panic if no handlers are given.

Fanout will call all the handlers concurrently via an errgroup. Thus the context passed to each will be canceled if any other handler fails. It is up to the inner handlers to decide if they should also cancel in this case or not.

The inner handlers _MUST NOT_ call `Ack()` or `Nack()` on the message!

If an inner handler panics, it may cause messages to get stuck indefinitely.

type OIDCToken added in v0.10.10

type OIDCToken = pubsub.OIDCToken

type PublishResult

type PublishResult = pubsub.PublishResult

type PublishSettings

type PublishSettings = pubsub.PublishSettings

type PushConfig added in v0.8.7

type PushConfig = pubsub.PushConfig

type PushMessage

type PushMessage = pubsubv1.PubsubMessage

type PushRequest

type PushRequest struct {
	Message      PushMessage `json:"message"`
	Subscription string      `json:"subscription"`
}

surprisingly, google doesn't export a type for this

type RealMessage

type RealMessage = pubsub.Message

for imports to have access to the real one they need for sending

type RetriableError

type RetriableError interface {
	error
	IsRetriable() bool
}

func AsRetriable

func AsRetriable(err error, retriable bool) RetriableError

type RetryPolicy

type RetryPolicy = pubsub.RetryPolicy

type Subscription

type Subscription interface {
	SubscriptionCommon
	Receive(ctx context.Context, msg MessageHandler) error
	ReceiveSettings() *pubsub.ReceiveSettings
	EnsureDefaultConfig(context.Context, ...func(*SubscriptionConfigToUpdate)) (SubscriptionConfig, error)
}

type SubscriptionConfig

type SubscriptionConfig = pubsub.SubscriptionConfig

type SubscriptionConfigToUpdate

type SubscriptionConfigToUpdate = pubsub.SubscriptionConfigToUpdate

type SubscriptionIterator

type SubscriptionIterator interface {
	Next() (Subscription, error)
	NextConfig() (*pubsub.SubscriptionConfig, error)
}

type Topic

type Topic interface {
	TopicCommon
	PublishSettings() *PublishSettings
	Subscriptions(context.Context) SubscriptionIterator

	// CreateSubscription lives on Client in the real API, but we move it here to
	// avoid worrying about the Topic member on the SubscriptionConfig struct
	CreateSubscription(ctx context.Context, id string, cfg SubscriptionConfig) (Subscription, error)

	// EnableMessageOrdering turns on ordered publishing. This must be done before
	// the first publish that uses an ordering key, and should be done before the
	// first publish overall to avoid unexpected behavior and data races.
	EnableMessageOrdering()
}

type TopicConfig

type TopicConfig = pubsub.TopicConfig

re-export for ease of use

type TopicConfigToUpdate

type TopicConfigToUpdate = pubsub.TopicConfigToUpdate

type TopicIterator

type TopicIterator interface {
	Next() (Topic, error)
	NextConfig() (*pubsub.TopicConfig, error)
}

Jump to

Keyboard shortcuts

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