awsmsg

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package awsmsg speaks to Amazon SQS and SNS with the standard library and the shared Signature Version 4 signer.

The same argument as s3put: the AWS SDK would double the size of the bill of materials for four API calls. SQS uses its JSON protocol (AWS JSON 1.0, X-Amz-Target AmazonSQS.<Action>), which AWS documents as the current one; SNS uses its query protocol, which is the only one it has. Both work against LocalStack and VPC endpoints through an endpoint override.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Region      string
	Credentials awsv4.Credentials
	// Endpoint overrides AWS's host: LocalStack, ElasticMQ, a VPC endpoint. Empty means AWS for the region.
	Endpoint string
	// HTTPClient defaults to one with a timeout longer than the longest SQS long poll (20s).
	HTTPClient *http.Client
}

Config locates a service and signs for it.

type Message

type Message struct {
	ID            string
	Body          string
	ReceiptHandle string
	// ReceiveCount is how many times SQS has delivered it, which says when a message keeps failing.
	ReceiveCount int
}

Message is one received message. It stays on the queue, invisible, until it is deleted or its visibility timeout runs out.

type SNS

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

SNS publishes to one topic.

func NewSNS

func NewSNS(cfg Config, topicARN string) (*SNS, error)

NewSNS builds a client for a topic, named by its ARN.

func (*SNS) FIFO

func (t *SNS) FIFO() bool

FIFO reports whether the topic is a FIFO topic.

func (*SNS) Publish

func (t *SNS) Publish(ctx context.Context, message, subject, group, dedup string) (string, error)

Publish sends one message. subject is optional; group and dedup are for FIFO topics.

type SQS

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

SQS sends to and receives from one queue.

func NewSQS

func NewSQS(cfg Config, queueURL string) (*SQS, error)

NewSQS builds a client for a queue, named by its URL.

func (*SQS) Delete

func (q *SQS) Delete(ctx context.Context, receiptHandle string) error

Delete removes a message that has been handled.

func (*SQS) FIFO

func (q *SQS) FIFO() bool

FIFO reports whether the queue is a FIFO queue, which needs a group id on every send.

func (*SQS) Receive

func (q *SQS) Receive(ctx context.Context, max, wait, visibility int) ([]Message, error)

Receive long-polls for up to max messages (1 to 10), waiting up to wait seconds (0 to 20).

func (*SQS) Send

func (q *SQS) Send(ctx context.Context, body, group, dedup string) (string, error)

Send puts one message on the queue. group and dedup are for FIFO queues and ignored otherwise.

Jump to

Keyboard shortcuts

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