pubsub

package
v0.1.95 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pubsub subscribes to message queues without linking any backend.

Subscribe dispatches through a registry. Each backend lives in its own subpackage (pubsub/sqs, pubsub/gcppubsub, pubsub/kafka, pubsub/nats) and is enabled explicitly by calling that subpackage's Install() once at startup; pubsub/all installs every backend. Nothing registers itself from init(), so importing pubsub alone pulls in no cloud SDK or gocloud driver.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNackUnsupported is returned by Message.Nack when the backend cannot
	// hand a message back for redelivery (Kafka, for example).
	ErrNackUnsupported = errors.New("pubsub: backend does not support nack")

	// ErrAlreadySettled is returned when a message is acked or nacked twice.
	ErrAlreadySettled = errors.New("pubsub: message already acked or nacked")

	// ErrSubscriptionClosed is returned by Receive once the subscription is shut down.
	ErrSubscriptionClosed = errors.New("pubsub: subscription is shut down")
)

Functions

func Register added in v0.1.92

func Register(kind Kind, opener Opener)

Register makes opener serve kind, replacing any earlier registration, so Install functions are idempotent.

Types

type Arn

type Arn struct {
	Partition string
	Service   string
	Region    string
	Account   string
	Resource  string
}

func ParseArn

func ParseArn(s string) (Arn, error)

e.g. arn:aws:sqs:us-east-2:444455556666:queue1

func (Arn) ToQueueURL

func (arn Arn) ToQueueURL() string

e.g. const queueURL = "https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue"

type BatchOptions added in v0.1.92

type BatchOptions struct {
	// Fetch retrieves the next batch, blocking (long-polling) as long as it
	// likes. An empty batch is not an error: Fetch is simply called again.
	Fetch func(ctx context.Context) ([]*Message, error)
	// Close releases backend resources; called once by Shutdown.
	Close func(ctx context.Context) error
}

BatchOptions configures NewBatchSubscription.

type KafkaConfig

type KafkaConfig struct {
	Brokers []string `json:"brokers"`
	Topic   string   `json:"topic"`
	Group   string   `json:"group"`
}

+kubebuilder:object:generate=true

func (*KafkaConfig) DeepCopy

func (in *KafkaConfig) DeepCopy() *KafkaConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KafkaConfig.

func (*KafkaConfig) DeepCopyInto

func (in *KafkaConfig) DeepCopyInto(out *KafkaConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (KafkaConfig) String

func (k KafkaConfig) String() string

type Kind added in v0.1.92

type Kind string

Kind identifies a queue backend.

const (
	KindSQS      Kind = "sqs"
	KindPubSub   Kind = "pubsub"
	KindKafka    Kind = "kafka"
	KindNATS     Kind = "nats"
	KindRabbitMQ Kind = "rabbitmq"
	KindMemory   Kind = "memory"
)

type MemoryConfig

type MemoryConfig struct {
	QueueName string `json:"queue"`
}

+kubebuilder:object:generate=true

func (*MemoryConfig) DeepCopy

func (in *MemoryConfig) DeepCopy() *MemoryConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MemoryConfig.

func (*MemoryConfig) DeepCopyInto

func (in *MemoryConfig) DeepCopyInto(out *MemoryConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (MemoryConfig) String

func (m MemoryConfig) String() string

type Message added in v0.1.92

type Message struct {
	// ID is an opaque identifier suitable for logging.
	ID       string
	Body     []byte
	Metadata map[string]string
	// contains filtered or unexported fields
}

Message is a received message. Exactly one of Ack or Nack must be called once the message has been handled; unsettled messages are redelivered by the backend after its own timeout.

func NewMessage added in v0.1.92

func NewMessage(o MessageOptions) *Message

NewMessage builds a Message; it is meant for backend implementations.

func (*Message) Ack added in v0.1.92

func (m *Message) Ack(ctx context.Context) error

Ack marks the message as processed so the backend does not redeliver it.

func (*Message) Nack added in v0.1.92

func (m *Message) Nack(ctx context.Context) error

Nack hands the message back for immediate redelivery.

type MessageOptions added in v0.1.92

type MessageOptions struct {
	ID       string
	Body     []byte
	Metadata map[string]string
	Ack      func(context.Context) error
	Nack     func(context.Context) error
}

MessageOptions builds a Message. Ack is required; a nil Nack makes Message.Nack return ErrNackUnsupported.

type NATSConfig

type NATSConfig struct {
	URL     string `json:"url,omitempty"`
	Subject string `json:"subject"`
	Queue   string `json:"queue,omitempty"`
}

+kubebuilder:object:generate=true

func (*NATSConfig) DeepCopy

func (in *NATSConfig) DeepCopy() *NATSConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NATSConfig.

func (*NATSConfig) DeepCopyInto

func (in *NATSConfig) DeepCopyInto(out *NATSConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (NATSConfig) String

func (n NATSConfig) String() string

type Opener added in v0.1.92

type Opener func(ctx commonsContext.Context, c QueueConfig) (Subscription, error)

Opener opens a subscription for the backend's section of a QueueConfig.

type PubSubConfig

type PubSubConfig struct {
	ProjectID                string `json:"project_id"`
	Subscription             string `json:"subscription"`
	connection.GCPConnection `json:",inline"`
}

+kubebuilder:object:generate=true

func (*PubSubConfig) DeepCopy

func (in *PubSubConfig) DeepCopy() *PubSubConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PubSubConfig.

func (*PubSubConfig) DeepCopyInto

func (in *PubSubConfig) DeepCopyInto(out *PubSubConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (PubSubConfig) String

func (p PubSubConfig) String() string

type QueueConfig

type QueueConfig struct {
	SQS      *SQSConfig    `json:"sqs,omitempty"`
	PubSub   *PubSubConfig `json:"pubsub,omitempty"`
	RabbitMQ *RabbitConfig `json:"rabbitmq,omitempty"`
	Memory   *MemoryConfig `json:"memory,omitempty"`
	Kafka    *KafkaConfig  `json:"kafka,omitempty"`
	NATS     *NATSConfig   `json:"nats,omitempty"`
}

+kubebuilder:object:generate=true

func (*QueueConfig) DeepCopy

func (in *QueueConfig) DeepCopy() *QueueConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new QueueConfig.

func (*QueueConfig) DeepCopyInto

func (in *QueueConfig) DeepCopyInto(out *QueueConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (QueueConfig) GetQueue

func (c QueueConfig) GetQueue() fmt.Stringer

func (QueueConfig) Kind added in v0.1.92

func (c QueueConfig) Kind() (Kind, error)

Kind reports which backend the config selects, in the same precedence as GetQueue.

type RabbitConfig

type RabbitConfig struct {
	URL   `json:",inline"`
	Queue string `json:"queue"`
}

+kubebuilder:object:generate=true

func (*RabbitConfig) DeepCopy

func (in *RabbitConfig) DeepCopy() *RabbitConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RabbitConfig.

func (*RabbitConfig) DeepCopyInto

func (in *RabbitConfig) DeepCopyInto(out *RabbitConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (RabbitConfig) String

func (r RabbitConfig) String() string

type SQSConfig

type SQSConfig struct {
	QueueArn    string `json:"queue"`
	RawDelivery bool   `json:"raw"`
	// Time in seconds to long-poll for messages, Default to 15, max is 20
	WaitTime                 int `json:"waitTime,omitempty"`
	connection.AWSConnection `json:",inline"`
}

+kubebuilder:object:generate=true

func (*SQSConfig) DeepCopy

func (in *SQSConfig) DeepCopy() *SQSConfig

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQSConfig.

func (*SQSConfig) DeepCopyInto

func (in *SQSConfig) DeepCopyInto(out *SQSConfig)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (SQSConfig) String

func (s SQSConfig) String() string

type Subscription added in v0.1.92

type Subscription interface {
	// Receive blocks until a message is available, ctx is done, or the
	// subscription is shut down (ErrSubscriptionClosed).
	Receive(ctx context.Context) (*Message, error)
	// Shutdown stops the subscription and releases its resources.
	Shutdown(ctx context.Context) error
}

Subscription delivers messages from one queue, one at a time.

func NewBatchSubscription added in v0.1.92

func NewBatchSubscription(o BatchOptions) Subscription

NewBatchSubscription adapts a batch-oriented backend (SQS, Pub/Sub pull) to Subscription: it buffers fetched batches, serves them one message at a time and, on Shutdown, nacks messages that were fetched but never delivered.

func Subscribe

Subscribe opens the subscription selected by c through the registered backend.

type URL

type URL struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Username string `json:"username"`
	Password string `json:"password"`
}

+kubebuilder:object:generate=true

func (*URL) DeepCopy

func (in *URL) DeepCopy() *URL

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new URL.

func (*URL) DeepCopyInto

func (in *URL) DeepCopyInto(out *URL)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (URL) String

func (u URL) String() string

Directories

Path Synopsis
Package all installs every pubsub backend.
Package all installs every pubsub backend.
Package gcppubsub subscribes to GCP Pub/Sub over the SDK-free cloud/gcp REST client.
Package gcppubsub subscribes to GCP Pub/Sub over the SDK-free cloud/gcp REST client.
Package kafka subscribes to Kafka topics through the gocloud.dev kafkapubsub driver.
Package kafka subscribes to Kafka topics through the gocloud.dev kafkapubsub driver.
Package nats subscribes to NATS subjects through the gocloud.dev natspubsub driver.
Package nats subscribes to NATS subjects through the gocloud.dev natspubsub driver.
Package sqs subscribes to AWS SQS queues over the SDK-free cloud/aws client.
Package sqs subscribes to AWS SQS queues over the SDK-free cloud/aws client.

Jump to

Keyboard shortcuts

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