Documentation ¶
Overview ¶
Package sqs provides a simple and basic wrapper client for interacting with AWS SQS (Amazon Simple Queue Service).
Based on github.com/aws/aws-sdk-go-v2/service/sqs, it abstracts away the complexities of the SQS protocol and provides a simplified interface.
This package includes functions for sending, receiving, and deleting messages.
It allows to specify custom message encoding and decoding functions, including serialization and encryption.
Index ¶
- Constants
- func DefaultMessageDecodeFunc(_ context.Context, msg string, data any) error
- func DefaultMessageEncodeFunc(_ context.Context, data any) (string, error)
- func MessageDecode(msg string, data any) error
- func MessageEncode(data any) (string, error)
- type Client
- func (c *Client) Delete(ctx context.Context, receiptHandle string) error
- func (c *Client) HealthCheck(ctx context.Context) error
- func (c *Client) Receive(ctx context.Context) (*Message, error)
- func (c *Client) ReceiveData(ctx context.Context, data any) (string, error)
- func (c *Client) Send(ctx context.Context, message string) error
- func (c *Client) SendData(ctx context.Context, data any) error
- type Message
- type Option
- func WithAWSOptions(opt awsopt.Options) Option
- func WithEndpointImmutable(url string) Option
- func WithEndpointMutable(url string) Option
- func WithMessageDecodeFunc(f TDecodeFunc) Option
- func WithMessageEncodeFunc(f TEncodeFunc) Option
- func WithSrvOptionFuncs(opt ...SrvOptionFunc) Option
- func WithVisibilityTimeout(t int32) Option
- func WithWaitTimeSeconds(t int32) Option
- type SQS
- type SrvOptionFunc
- type TDecodeFunc
- type TEncodeFunc
Constants ¶
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 DefaultMessageDecodeFunc ¶ added in v1.85.0
DefaultMessageDecodeFunc is the default function to decode a message for ReceiveData(). The value underlying data must be a pointer to the correct type for the next data item received.
func DefaultMessageEncodeFunc ¶ added in v1.85.0
DefaultMessageEncodeFunc is the default function to encode and serialize the input data for SendData().
func MessageDecode ¶
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 ¶
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 ¶
New creates a new instance of the SQS client wrapper. msgGroupID is required for FIFO queues.
func (*Client) HealthCheck ¶
HealthCheck checks if the current queue is present in the current region and returns an error otherwise.
func (*Client) Receive ¶
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 ¶
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.
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 ¶
WithAWSOptions allows to add an arbitrary AWS options.
func WithEndpointImmutable ¶ added in v1.91.0
WithEndpointImmutable sets an immutable endpoint.
func WithEndpointMutable ¶ added in v1.91.0
WithEndpointMutable sets a mutable endpoint.
func WithMessageDecodeFunc ¶ added in v1.85.0
func WithMessageDecodeFunc(f TDecodeFunc) Option
WithMessageDecodeFunc allow to replace DefaultMessageDecodeFunc(). This function used by ReceiveData() to decode a message encoded with messageEncodeFunc to the provided data object. The value underlying data must be a pointer to the correct type for the next data item received.
func WithMessageEncodeFunc ¶ added in v1.85.0
func WithMessageEncodeFunc(f TEncodeFunc) Option
WithMessageEncodeFunc allow to replace DefaultMessageEncodeFunc. This function used by SendData() to encode and serialize the input data to a string compatible with SQS.
func WithSrvOptionFuncs ¶ added in v1.91.0
func WithSrvOptionFuncs(opt ...SrvOptionFunc) Option
WithSrvOptionFuncs allows to specify specific options.
func WithVisibilityTimeout ¶
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 ¶
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.
type SrvOptionFunc ¶ added in v1.91.0
SrvOptionFunc is an alias for this service option function.
type TDecodeFunc ¶ added in v1.85.0
TDecodeFunc is the type of function used to replace the default message decoding function used by ReceiveData().