Documentation ¶
Overview ¶
Package squeues implements a concurrent dispatcher for AWS SQS queue messages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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.