squeues

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package squeues implements a concurrent dispatcher for AWS SQS queue messages.

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultPollTime is default the max duration to wait for messages.
	// The max allow by the AWS SQS API is 20 seconds.
	DefaultPollTime = 20 * time.Second

	// DefaultInitialVisibilityTimeout is the default initial message visibility timeout.
	DefaultInitialVisibilityTimeout = 5 * time.Second

	// DefaultMaxVisibilityTimeout is the default max message visibility timeout.
	DefaultMaxVisibilityTimeout = 60 * time.Second
)

Functions

func Region

func Region(URL string) (string, error)

Region parses an SQS queue URL to return the AWS region it's in.

Types

type Dispatcher

type Dispatcher struct {

	// Maximum number of concurrent messages to handle.
	// Zero (the default) is no limit.
	MaxConcurrent int

	// Max seconds to wait for messages.
	// Defaults to DefaultPollTime.
	PollTime time.Duration

	// Initial message visibility timeout.
	// Defaults to DefaultInitialVisibilityTimeout.
	InitialVisibilityTimeout time.Duration

	// Max message visibility timeout.
	// Defaults to DefaultMaxVisibilityTimeout.
	MaxVisibilityTimeout time.Duration
	// contains filtered or unexported fields
}

Dispatcher is a dispatcher for AWS SQS messages, executing a Handler for each message received.

func New

func New(client sqsiface.SQSAPI, queueURL string) *Dispatcher

New returns a new Dispatcher.

func (*Dispatcher) Run

func (q *Dispatcher) Run(handler Handler) error

Run consumes messages from the SQS queue and calls h.Handle() as a goroutine for each.

While the Handler is running, the message will periodically have its visibility timeout updated to keep the message reserved. If the Handler or any communication with AWS returns a error, the context passed to the Handler will be canceled and the error returned. If the Handler returns without error, the message will be deleted from SQS.

Unless there is an error, Run() will block forever. If you need the ability to cancel, use RunWithContext().

func (*Dispatcher) RunWithContext

func (q *Dispatcher) RunWithContext(ctx context.Context, handler Handler) error

RunWithContext is the same as Run() but passing a context.

type Handler

type Handler interface {
	Handle(context.Context, *sqs.Message) error
}

Handler is an interface for handling messages received from an SQS queue. It's passed into SQS.Run().

func FuncHandler

func FuncHandler(fn func(context.Context, *sqs.Message) error) Handler

FuncHandler returns a simple Handler wrapper around a function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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