sqs

package
v0.63.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sqs provides a native consumer for AWS SQS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Batch

type Batch interface {
	// Messages of the batch.
	Messages() []Message
	// ACK deletes all messages from SQS with a single call and completes the all the message tracing spans.
	// In case the action will not manage to ACK all the messages, a slice of the failed messages will be returned.
	ACK() ([]Message, error)
	// NACK leaves all messages in the queue and completes the all the message tracing spans.
	NACK()
}

Batch interface for multiple AWS SQS messages.

type Component

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

Component implementation of a async component.

func New

func New(name, queueName string, sqsAPI sqsiface.SQSAPI, proc ProcessorFunc, oo ...OptionFunc) (*Component, error)

New creates a new component with support for functional configuration.

func (*Component) Run

func (c *Component) Run(ctx context.Context) error

Run starts the consumer processing loop messages.

type Message

type Message interface {
	// Context will contain the context to be used for processing.
	// Each context will have a logger setup which can be used to create a logger from context.
	Context() context.Context
	// ID of the message.
	ID() string
	// Body of the message.
	Body() []byte
	// Message will contain the raw SQS message.
	Message() *sqs.Message
	// Span contains the tracing span of this message.
	Span() opentracing.Span
	// ACK deletes the message from the queue and completes the tracing span.
	ACK() error
	// NACK leaves the message in the queue and completes the tracing span.
	NACK()
}

Message interface for AWS SQS message.

type OptionFunc

type OptionFunc func(*Component) error

OptionFunc definition for configuring the component in a functional way.

func MaxMessages

func MaxMessages(maxMessages int64) OptionFunc

MaxMessages option for setting the max number of messages fetched. Allowed values are between 1 and 10. If messages can be processed very quickly, maxing out this value is fine, otherwise having a high value is risky as it might trigger the visibility timeout. Having a value too small isn't recommended either, as it increases the number of SQS API requests, thus AWS costs.

func PollWaitSeconds

func PollWaitSeconds(pollWaitSeconds int64) OptionFunc

PollWaitSeconds sets the wait time for the long polling mechanism in seconds. Allowed values are between 0 and 20. 0 enables short polling.

func QueueStatsInterval

func QueueStatsInterval(interval time.Duration) OptionFunc

QueueStatsInterval sets the interval at which we retrieve AWS SQS stats.

func Retries

func Retries(count uint) OptionFunc

Retries sets the error retries of the component.

func RetryWait

func RetryWait(interval time.Duration) OptionFunc

RetryWait sets the wait period for the component retry.

func VisibilityTimeout

func VisibilityTimeout(visibilityTimeout int64) OptionFunc

VisibilityTimeout sets the time a message is invisible after it has been requested. This is a built in resiliency mechanism so that, should the consumer fail to acknowledge the message within such timeout, it will become visible again and thus available for retries. Allowed values are between 0 and and 12 hours in seconds.

type ProcessorFunc

type ProcessorFunc func(context.Context, Batch)

ProcessorFunc definition of a async processor.

Jump to

Keyboard shortcuts

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