sqs

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 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(opts ...Option) func(gas.ConfigProvider, gas.Logger) *Service

New captures options and returns a DI-injectable constructor.

Types

type Config

type Config struct {
	env.WithGasEnv

	Queue Settings
}

Config holds SQS queue settings.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with sensible defaults.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the Config for correctness.

type Option

type Option func(*Service)

Option configures a Service.

func WithClient

func WithClient(client sqsClient) Option

WithClient injects a pre-configured SQS client. Useful for testing or when the caller manages AWS credentials externally.

func WithConfig

func WithConfig(cfg *Config) Option

WithConfig sets a custom configuration.

type Service

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

Service is an SQS-backed queue implementing gas.Service and gas.JobQueueProvider.

func (*Service) Ack

func (s *Service) Ack(ctx context.Context, queueURL string, job gas.Job) error

Ack acknowledges a job by deleting it from the queue.

func (*Service) CheckReady

func (s *Service) CheckReady(_ context.Context) error

CheckReady reports whether the service is ready to accept traffic. Returns an error before Init has run or after Close has been called.

func (*Service) Client

func (s *Service) Client() *awssqs.Client

Client returns the underlying *sqs.Client for advanced operations beyond the JobQueueProvider interface (e.g. CreateQueue, PurgeQueue, GetQueueAttributes). Returns nil if a custom sqsClient was injected via WithClient that is not an *sqs.Client.

func (*Service) Close

func (s *Service) Close() error

Close marks the service as closed.

func (*Service) Dequeue

func (s *Service) Dequeue(ctx context.Context, queueURL string, maxMessages int, wait time.Duration) ([]gas.Job, error)

Dequeue receives messages from the specified SQS queue.

func (*Service) Enqueue

func (s *Service) Enqueue(ctx context.Context, queueURL string, payload []byte, opts ...gas.EnqueueOption) error

Enqueue sends a message to the specified SQS queue.

func (*Service) Init

func (s *Service) Init() error

Init validates the configuration and creates the SQS client.

func (*Service) Nack

func (s *Service) Nack(ctx context.Context, queueURL string, job gas.Job) error

Nack makes a job immediately available for reprocessing by setting its visibility timeout to zero.

func (*Service) Name

func (s *Service) Name() string

Name returns the service identifier.

type Settings

type Settings struct {
	// Region is the AWS region for the SQS service.
	Region string

	// Endpoint is an optional custom endpoint URL (e.g. for LocalStack).
	// Empty means use the default AWS endpoint.
	Endpoint string

	// AccessKeyID is the AWS access key ID for static credentials.
	// If empty, the default AWS credential chain is used.
	AccessKeyID string

	// SecretAccessKey is the AWS secret access key for static credentials.
	// If empty, the default AWS credential chain is used.
	SecretAccessKey string

	// VisibilityTimeout is how long a dequeued message stays invisible
	// to other consumers. SQS max is 12 hours.
	VisibilityTimeout time.Duration

	// WaitTimeSeconds is the long-poll duration for ReceiveMessage calls.
	// Must be 0-20 (SQS hard limit).
	WaitTimeSeconds int
}

Settings represents the configuration for the SQS queue service.

Jump to

Keyboard shortcuts

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