pubsub

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any](client *pubsub.Client) function.CmdFunc[T]

New returns CmdFunc for cloudevents command.

Types

type Helper

type Helper[T any] struct {
	// contains filtered or unexported fields
}

Helper assists in creating event handlers for Pub/Sub with multiple topics.

func NewHelper

func NewHelper[T any](client *pubsub.Client, handler function.Handler[T]) *Helper[T]

NewHelper returns a new Helper with default options.

func NewHelperWithOptions

func NewHelperWithOptions[T any](client *pubsub.Client, handler function.Handler[T], options *Options) *Helper[T]

NewHelperWithOptions returns a new Helper with custom options.

func (*Helper[T]) Run added in v1.6.2

func (h *Helper[T]) Run(ctx context.Context) error

Run receives the messages of every subscription concurrently until ctx is done. Then it pulls no new message, waits for the handlers to finish the ones they hold, and returns. When a subscription cannot be received, for instance because it does not exist, Run stops the others and returns that error, so the app fails instead of running without it.

func (*Helper[T]) Start deprecated

func (h *Helper[T]) Start()

Start runs the helper with no way to stop it, and logs the error Run returns.

Deprecated: use Run with the run context, so the app stops on SIGTERM and fails when a subscription cannot be received.

type Options

type Options struct {
	Subscriptions  []string
	Concurrency    int64         // Max concurrent workers
	Backoff        bool          // Enable backoff
	BackoffBase    time.Duration // Base backoff duration
	MaxBackoff     time.Duration // Max backoff duration
	RetryLimit     int           // Limit retries, -1 for infinite retries
	ProcessTimeout time.Duration // Timeout for processing messages
}

Options can be used to create customized handler.

func DefaultOptions

func DefaultOptions() (*Options, error)

DefaultOptions returns options based in config.

type Subscriber

type Subscriber[T any] struct {
	// contains filtered or unexported fields
}

Subscriber contains the Pub/Sub client, handler function, and options

func NewSubscriber

func NewSubscriber[T any](client *pubsub.Client, handler function.Handler[T], subscription string, options *Options) *Subscriber[T]

NewSubscriber returns a subscriber listener.

func (*Subscriber[T]) Subscribe

func (l *Subscriber[T]) Subscribe(ctx context.Context) error

Subscribe receives the messages of the subscription until ctx is done, and returns once the handlers finished the ones they hold. It returns an error naming the subscription when it cannot be received.

Jump to

Keyboard shortcuts

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