sqs

package
v1.80.2 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sqs provides a basic client for AWS SQS (Amazon Simple Queue Service).

Index

Constants

View Source
const (
	// DefaultWaitTimeSeconds is the default duration (in seconds) for which the call waits for a message to arrive in the queue before returning.
	// This must be between 0 and 20 seconds.
	DefaultWaitTimeSeconds = 20

	// DefaultVisibilityTimeout is the default duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request.
	DefaultVisibilityTimeout = 600
)

Variables

This section is empty.

Functions

func MessageDecode

func MessageDecode(msg string, data any) error

MessageDecode decodes a message encoded with MessageEncode to the provided data object. The value underlying data must be a pointer to the correct type for the next data item received.

func MessageEncode

func MessageEncode(data any) (string, error)

MessageEncode encodes and serialize the input data to a string compatible with SQS.

Types

type Client

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

Client is a wrapper for the SQS client in the AWS SDK.

func New

func New(ctx context.Context, queueURL, msgGroupID string, opts ...Option) (*Client, error)

New creates a new instance of the SQS client wrapper. msgGroupID is required for FIFO queues.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, receiptHandle string) error

Delete deletes the specified message from the queue.

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck checks if the current queue is present in the current region and returns an error otherwise.

func (*Client) Receive

func (c *Client) Receive(ctx context.Context) (*Message, error)

Receive retrieves a raw string message from the queue. This function will wait up to WaitTimeSeconds seconds for a message to be available, otherwise it will return nil. Once retrieved, a message will not be visible for up to VisibilityTimeout seconds. Once processed the message should be removed from the queue by calling the Delete method.

func (*Client) ReceiveData

func (c *Client) ReceiveData(ctx context.Context, data any) (string, error)

ReceiveData retrieves a message from the queue, extract its content in the data and returns the ReceiptHandle. The value underlying data must be a pointer to the correct type for the next data item received. This function will wait up to WaitTimeSeconds seconds for a message to be available, otherwise it will return an empty ReceiptHandle. Once retrieved, a message will not be visible for up to VisibilityTimeout seconds. Once processed the message should be removed from the queue by calling the Delete method. In case of decoding error the returned receipt handle will be not empty, so it can be used to delete the message.

func (*Client) Send

func (c *Client) Send(ctx context.Context, message string) error

Send delivers a raw string message to the queue.

func (*Client) SendData

func (c *Client) SendData(ctx context.Context, data any) error

SendData delivers the specified data as message to the queue.

type Message

type Message struct {
	// Body is the message content and can contain: JSON, XML or plain text.
	Body string

	// ReceiptHandle is the identifier used to delete the message.
	ReceiptHandle string
}

Message represents a message in the queue.

type Option

type Option func(*cfg)

Option is a type to allow setting custom client options.

func WithAWSOptions

func WithAWSOptions(opt awsopt.Options) Option

WithAWSOptions allows to add an arbitrary AWS options.

func WithVisibilityTimeout

func WithVisibilityTimeout(t int32) Option

WithVisibilityTimeout overrides the default duration (in seconds) that the received messages are hidden from subsequent retrieve requests after being retrieved by a ReceiveMessage request. Values range: 0 to 43200. Maximum: 12 hours.

func WithWaitTimeSeconds

func WithWaitTimeSeconds(t int32) Option

WithWaitTimeSeconds overrides the default duration (in seconds) for which the call waits for a message to arrive in the queue before returning. Values range: 0 to 20 seconds.

type SQS

type SQS interface {
	DeleteMessage(ctx context.Context, params *sqs.DeleteMessageInput, optFns ...func(*sqs.Options)) (*sqs.DeleteMessageOutput, error)
	GetQueueAttributes(ctx context.Context, params *sqs.GetQueueAttributesInput, optFns ...func(*sqs.Options)) (*sqs.GetQueueAttributesOutput, error)
	ReceiveMessage(ctx context.Context, params *sqs.ReceiveMessageInput, optFns ...func(*sqs.Options)) (*sqs.ReceiveMessageOutput, error)
	SendMessage(ctx context.Context, params *sqs.SendMessageInput, optFns ...func(*sqs.Options)) (*sqs.SendMessageOutput, error)
}

SQS represents the mockable functions in the AWS SDK SQS client.

Jump to

Keyboard shortcuts

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