sqs

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 11 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerFunc

type HandlerFunc func(ctx context.Context, batch []Message)

HandlerFunc is invoked for each received batch.

The handler should handle errors internally. Messages are only deleted if your handler calls `Message.Mark()` on them.

type Message

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

Message wraps an SQS message and provides a best-effort Mark() API for background deletion.

func (Message) Mark

func (m Message) Mark()

Mark best-effort enqueues this message for background deletion. It is a no-op if marking isn't configured, or if required fields are missing.

func (Message) Raw

func (m Message) Raw() types.Message

Raw returns the underlying AWS SDK message. This keeps the wrapper non-leaky while still allowing full access when needed.

type Option

type Option func(*Options) error

Option mutates Options (variadic functional options style).

func WithBatchSize

func WithBatchSize(n int) Option

func WithDeleteBatchSize

func WithDeleteBatchSize(n int) Option

func WithDeleteBatchWindow

func WithDeleteBatchWindow(d time.Duration) Option

func WithLogger

func WithLogger(l *slog.Logger) Option

func WithQueueURL

func WithQueueURL(url string) Option

func WithSQSClient

func WithSQSClient(c sqsClient) Option

func WithVisibilityTimeoutSeconds

func WithVisibilityTimeoutSeconds(n int32) Option

func WithWaitTimeSeconds

func WithWaitTimeSeconds(n int32) Option

func WithWorkerCount

func WithWorkerCount(n int) Option

type Options

type Options struct {
	// Required
	QueueURL string

	// Optional. If nil, New() should create a client using gommon/pkg/aws GetConfig().
	Client sqsClient

	// Optional. If nil, the worker should use slog.Default().
	Logger *slog.Logger

	// Concurrency
	WorkerCount int

	// Batching
	// BatchSize controls how many messages are passed to your handler per job.
	// Note: SQS ReceiveMessage MaxNumberOfMessages is <= 10, and the worker currently
	// maps receive batch == handler batch, so BatchSize must be 1..10.
	BatchSize int

	// ReceiveMessage tuning
	// WaitTimeSeconds controls SQS long-polling (0..20).
	WaitTimeSeconds int32

	// VisibilityTimeoutSeconds overrides the per-receive visibility timeout.
	// If nil, the queue default visibility timeout applies.
	VisibilityTimeoutSeconds *int32

	// Delete batching
	// DeleteBatchSize controls max entries per DeleteMessageBatch call (1..10).
	DeleteBatchSize int
	// DeleteBatchWindow controls periodic flushing even if the delete batch isn't full.
	DeleteBatchWindow time.Duration
}

Options holds all configurable settings for Worker construction.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns a fully-populated Options struct with sane defaults. QueueURL is still required and must be set via WithQueueURL (or directly) before validation.

func (Options) Validate

func (o Options) Validate() error

Validate checks the Options for correctness.

type Worker

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

func New

func New(handler HandlerFunc, optFns ...Option) (*Worker, error)

New constructs a Worker using DefaultOptions(), applies any variadic options, then validates. Handler is required. QueueURL must be provided via WithQueueURL(...).

func (*Worker) Start

func (w *Worker) Start(ctx context.Context) error

Start runs the poller, workers, and background deleter until ctx is cancelled. It returns when shutdown is complete. Any poll error is returned.

Jump to

Keyboard shortcuts

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