sqs

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package sqs is doze-aws's ground-up, pure-Go SQS-compatible service: no LocalStack, no JVM. It speaks both wire protocols (AWS JSON 1.0 used by modern SDKs and the legacy Query/XML protocol used by aws-sdk-go v1-era clients), persists to a bbolt store under the data directory, and supports visibility timeout, delay, retention, message attributes, long polling, FIFO queues (group ordering + deduplication), dead-letter redrive, queue tags, and message move tasks.

See docs/api-support/sqs.md for the operation-by-operation support table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attr

type Attr struct {
	DataType    string `json:"data_type"`
	StringValue string `json:"string_value,omitempty"`
	BinaryValue []byte `json:"binary_value,omitempty"`
}

Attr is a message attribute (String/Number use StringValue; Binary uses BinaryValue).

type Message

type Message struct {
	ID            string          `json:"id"`
	Body          string          `json:"body"`
	Attrs         map[string]Attr `json:"attrs,omitempty"`
	MD5Body       string          `json:"md5_body"`
	MD5Attrs      string          `json:"md5_attrs,omitempty"`
	Sent          int64           `json:"sent"`       // unixnano
	VisibleAt     int64           `json:"visible_at"` // unixnano; <= now => visible
	ReceiveCount  int             `json:"receive_count"`
	FirstReceived int64           `json:"first_received"` // unixnano, 0 if never
	GroupID       string          `json:"group_id,omitempty"`
	DedupID       string          `json:"dedup_id,omitempty"`
	Seq           uint64          `json:"seq"`
}

Message is one stored message.

func (*Message) Handle

func (m *Message) Handle() string

Handle encodes the message's position AND identity; Delete/ChangeVisibility decode both and verify the id so a stale handle can't act on a different message that later reused the same sequence number.

type MoveTask

type MoveTask struct {
	Handle      string `json:"handle"`
	Status      string `json:"status"` // COMPLETED | FAILED
	Source      string `json:"source"` // queue name
	Destination string `json:"destination"`
	Moved       int    `json:"moved"`
	StartedAt   int64  `json:"started_at"` // unix seconds
	FailureWhy  string `json:"failure_why,omitempty"`
}

MoveTask records one message move task. Local moves are synchronous, so a stored task is always in a terminal state.

type Options

type Options struct {
	// DataDir holds the bbolt store (sqs.bolt). Required.
	DataDir string
	// Peers is accepted for constructor uniformity; SQS initiates no
	// cross-service calls today (Lambda event source mappings poll SQS from
	// the Lambda side).
	Peers peers.Directory
	// Logf receives log lines; nil discards.
	Logf func(format string, args ...any)
	// Clock overrides time.Now in tests.
	Clock func() time.Time
}

Options configures the service.

type Queue

type Queue struct {
	Name              string `json:"name"`
	FIFO              bool   `json:"fifo"`
	ContentBasedDedup bool   `json:"content_based_dedup"`
	VisibilityTimeout int    `json:"visibility_timeout"` // seconds
	DelaySeconds      int    `json:"delay_seconds"`
	RetentionPeriod   int    `json:"retention_period"` // seconds
	MaxMessageSize    int    `json:"max_message_size"`
	WaitTimeSeconds   int    `json:"wait_time_seconds"`  // default receive long-poll
	DeadLetterTarget  string `json:"dead_letter_target"` // target queue name, "" if none
	MaxReceiveCount   int    `json:"max_receive_count"`
	Created           int64  `json:"created"` // unix seconds

	Tags map[string]string `json:"tags,omitempty"`
}

Queue is a queue's durable definition.

type Server

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

Server is the SQS service: an http.Handler speaking both SQS wire protocols, and an io.Closer that stops the janitor and closes the store.

func New

func New(opts Options) (*Server, error)

New opens the bbolt store under DataDir and starts the retention janitor.

func (*Server) Close

func (s *Server) Close() error

Close stops the janitor goroutine, then closes the bbolt DB.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Store

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

Store is the bbolt-backed SQS state.

func (*Store) Attributes

func (s *Store) Attributes(name string) (map[string]string, error)

Attributes returns the GetQueueAttributes view of a queue.

func (*Store) CancelMessageMoveTask

func (s *Store) CancelMessageMoveTask(handle string) error

CancelMessageMoveTask always fails locally: moves complete synchronously, so by the time a cancel arrives the task is already terminal — which is exactly what AWS reports for a finished task.

func (*Store) ChangeVisibility

func (s *Store) ChangeVisibility(queue, handle string, timeout int) error

func (*Store) CreateQueue

func (s *Store) CreateQueue(name string, attrs map[string]string, tags map[string]string) (*Queue, error)

CreateQueue creates (or, idempotently, updates the attributes of) a queue.

func (*Store) DeadLetterSourceQueues

func (s *Store) DeadLetterSourceQueues(dlq string) ([]string, error)

DeadLetterSourceQueues lists the queues whose redrive policy targets dlq.

func (*Store) Delete

func (s *Store) Delete(queue, handle string) error

func (*Store) DeleteQueue

func (s *Store) DeleteQueue(name string) error

func (*Store) ListMessageMoveTasks

func (s *Store) ListMessageMoveTasks(source string, max int) ([]MoveTask, error)

ListMessageMoveTasks returns the recorded tasks for a source queue, newest first, up to max.

func (*Store) ListQueues

func (s *Store) ListQueues(prefix string) ([]string, error)

func (*Store) Peek

func (s *Store) Peek(queue string, max int) ([]Message, error)

Peek returns up to max currently-visible messages in queue (FIFO) order WITHOUT consuming them: it never changes visibility, never increments the receive count, and ignores FIFO group locking — so it shows the FULL queue contents (every message, not just the head of each message group, the way a plain Receive does). Purely read-only; the returned handles are still valid for Delete.

func (*Store) Purge

func (s *Store) Purge(queue string) error

func (*Store) Receive

func (s *Store) Receive(queue string, max, waitSec int, visibilityOverride int) ([]Message, error)

Receive returns up to max visible messages, applying visibility timeout, FIFO group locking, DLQ redrive, and retention. waitSec long-polls when empty.

func (*Store) Send

func (s *Store) Send(queue, body string, attrs map[string]Attr, delay int, groupID, dedupID string) (*Message, error)

Send enqueues a message. delay<0 means "use the queue default".

func (*Store) SetAttributes

func (s *Store) SetAttributes(name string, attrs map[string]string) error

func (*Store) StartMessageMoveTask

func (s *Store) StartMessageMoveTask(source, dest string) (*MoveTask, error)

StartMessageMoveTask moves every currently-stored message from source to dest, synchronously — the local equivalent of a DLQ redrive. AWS moves asynchronously with rate control; locally the volumes are small enough that completing inline is simpler and deterministic.

func (*Store) Sweep

func (s *Store) Sweep()

Sweep drops retention-expired messages and prunes stale dedup entries across every queue. Receive does this lazily for read queues; a periodic Sweep also reclaims write-only queues so nothing grows unbounded.

func (*Store) TagQueue

func (s *Store) TagQueue(name string, tags map[string]string) error

TagQueue merges tags into a queue's tag set.

func (*Store) Tags

func (s *Store) Tags(name string) (map[string]string, error)

Tags returns a queue's tag set.

func (*Store) UntagQueue

func (s *Store) UntagQueue(name string, keys []string) error

UntagQueue removes the named tag keys.

Jump to

Keyboard shortcuts

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