Documentation
¶
Index ¶
- type FailedMessage
- type HandlerFunc
- type Message
- type Option
- func WithBatchSize(n int) Option
- func WithDeleteBatchSize(n int) Option
- func WithDeleteBatchWindow(d time.Duration) Option
- func WithLogger(l *slog.Logger) Option
- func WithQueueURL(url string) Option
- func WithSQSClient(c sqsClient) Option
- func WithVisibilityTimeoutSeconds(n int32) Option
- func WithWaitTimeSeconds(n int32) Option
- func WithWorkerCount(n int) Option
- type Options
- type SendError
- type Sender
- type Worker
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FailedMessage ¶ added in v0.15.0
type FailedMessage struct {
// Index is the body's position in the slice passed to SendBatch.
Index int
Code string
Message string
SenderFault bool
}
FailedMessage is one body SQS rejected.
type HandlerFunc ¶
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.
type Option ¶
Option mutates Options (variadic functional options style).
func WithBatchSize ¶
func WithDeleteBatchSize ¶
func WithDeleteBatchWindow ¶
func WithLogger ¶
func WithQueueURL ¶
func WithSQSClient ¶
func WithSQSClient(c sqsClient) Option
func WithWaitTimeSeconds ¶
func WithWorkerCount ¶
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.
type SendError ¶ added in v0.15.0
type SendError struct {
Failed []FailedMessage
}
SendError lists the bodies SQS rejected while accepting the rest of their batch.
type Sender ¶ added in v0.15.0
type Sender struct {
// contains filtered or unexported fields
}
Sender sends messages to one queue. It is the producing side of Worker.
func DefaultSender ¶ added in v0.15.0
DefaultSender builds a sender with a 5 second timeout and 3 total attempts.
func NewSender ¶ added in v0.15.0
NewSender builds a sender for queueURL. timeout is the deadline for each SendMessageBatch call. maxRetryAttempts is passed to the SDK as MaxAttempts, which counts the first attempt.
func (*Sender) SendBatch ¶ added in v0.15.0
SendBatch sends every body, ten per SendMessageBatch call, and returns how many SQS accepted.
Bodies SQS rejects one at a time do not stop the send: the remaining batches still go, and the returned error is a *SendError naming each rejected body by its index in bodies. A failed call stops the send, and the error wraps the SDK error along with any *SendError from earlier batches. An empty body is rejected before anything is sent.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}