Documentation ¶
Overview ¶
Package sqshandler implements a
Index ¶
Constants ¶
const ( DefaultIniTimeout = 5 DefaultMaxTimeout = 300 DefaultMultiplier = 2.5 DefaultRandFactor = 0.3 )
Default values for BackOff.
const SQSMaxVisibility = 43200
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackOff ¶
BackOff defines values used for calculating a message's exponential backoff in case of a transient failure by altering its visibility timeout. Each retry attempt will take exponentially longer based on the amount of delivery attempts (attribute `ApproximateReceiveCount`) until the message is either delivered or sent to a DLQ, according to the following parameters:
InitTimeoutSec ¶
Defines the initial timeout value for the message, in seconds, ranging from 0 to 43200 (12h, the maximum value accepted by AWS).
MaxTimeoutSec ¶
Defines the maximum timeout value for the message, in seconds, ranging from 0 to 43200 (12h, the maximum value accepted by AWS). Note that this does not include jitter ranges, unless the final value exceeds 43200.
For example, if MaxTimeoutSec is set to 6, and RandFactor is set to 0.5, the final timeout value can be any integer from 3 to 9. However if MaxTimeoutSec is set to 43200, the values will range from 21600 to 43200 (instead of 64800).
Multiplier ¶
Defines the scaling factor of the exponential function. Note that the resulting values will be rounded down, as AWS only accepts positive interger values. Setting this value to 1 will linearize the backoff curve.
RandFactor ¶
Adds a jitter factor to the function by making it so that the final timeout value ranges in [interval * (1 ± RandFactor)], rounded down. Setting this value to 0 disables it.
Example ¶
For the default values 5, 300, 2.5 and 0.2:
D Timeout Timeout Timeout # (Raw) (NoJitter) (WithJitter) 1 5 5 [4, 6] 2 12.5 12 [9, 14] 3 31.25 31 [24, 37] 4 78.125 78 [62, 93] 5 195.3125 195 [156, 234] 6 488.28125 300 [240, 360] 7 1220.7031 300 [240, 360]
Based on `https://github.com/cenkalti/backoff/blob/v4/exponential.go`.
For more information about message visibility, see: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-visibility-timeout.html.
func NewBackOff ¶
func NewBackOff() BackOff
NewBackoff creates an instance of BackOff using default values.
type Handler ¶
type Handler struct { BackOff BackOff Context context.Context FailureDlqURL string SQSClient SQSClient }
func New ¶
New creates an instance of BatchHandler with default values for exponential backoff on retries, no DLQ for failed messages and a sqs.Client with default configurations.
func (*Handler) HandleEvent ¶
func (b *Handler) HandleEvent(event *events.SQSEvent, worker Worker) (events.SQSEventResponse, error)
HandleEvent
type Result ¶
type Result struct { Message *events.SQSMessage `validate:"required"` Status Status `validate:"oneof=FAILURE RETRY SKIP SUCCESS"` Error error }
type SQSClient ¶
type SQSClient interface { ChangeMessageVisibility(context.Context, *sqs.ChangeMessageVisibilityInput, ...func(*sqs.Options)) (*sqs.ChangeMessageVisibilityOutput, error) SendMessage(context.Context, *sqs.SendMessageInput, ...func(*sqs.Options)) (*sqs.SendMessageOutput, error) DeleteMessage(context.Context, *sqs.DeleteMessageInput, ...func(*sqs.Options)) (*sqs.DeleteMessageOutput, error) }
Interface to enable mocking of a SQSClient, usually for testing purposes