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 ¶
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 ¶
Types ¶
type Arn ¶
func (Arn) ToQueueURL ¶
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 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.
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 ¶
+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 ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SQSConfig.
func (*SQSConfig) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
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 ¶
func Subscribe(ctx commonsContext.Context, c QueueConfig) (Subscription, error)
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 ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new URL.
func (*URL) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
Source Files
¶
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. |