modulepackage
0.2.3
Repository: https://github.com/barrett370/sqs-processor.git
Documentation: pkg.go.dev
# README
SQS Processor
Attempt to wrap AWS SQS client with functionality similar to that of the gcloud pub/sub client.
Usage
The processor will simply run a given ProcessFunc
over any messages found on a given SQS queue. ProcessFunc
takes the sqs message body in as a string and decides how to decode and action on the message.
The ProcessFunc
must return either ProcessResultAck
or ProcessResultNack
. Ack
implies a success and leads to the message being deleted from the queue, whereas Nack
will re-publish the message to the queue.
Example
import (
"context"
"time"
"github.com/barrett370/sqs-processor/middleware"
sqsprocessor "github.com/barrett370/sqs-processor"
"github.com/aws/aws-sdk-go-v2/service/sqs"
)
type messageBody struct {
ID string
Action EnumType
}
func (s *service) process(ctx context.Context, message messageBody) (ret sqsprocessor.ProcessResult) {
err := s.DoAction(message.ID, message.Action)
if err == nil {
ret = sqsprocessor.ProcessResultAck
}
return
}
func main() {
// initialise v2 sqs client
c := newClient()
config := sqsprocessor.ProcessorConfig{
Receive: sqs.ReceiveMessageInput{
WaitTimeSeconds: 10,
MaxNumberOfMessages: 10,
VisibilityTimeout: 2,
},
NumWorkers: 10,
Backoff: time.Second,
}
p := sqsprocessor.NewProcessor(c, config)
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
cleanup := func() {
cancel()
<- done
}
go func() {
p.Process(ctx, middleware.JSONDecode(svc.process))
close(done)
}()
// some other code
cleanup()
}
# Packages
No description provided by the author
# Functions
New returns a pointer to a new Processor given a config and sqs client.
# Constants
ProcessResultAck indicates that the
ProcessFunc was successful in processing
the message.
ProcessResultNack indicates that the
ProcessFunc either does not want to
process a message or has failed to,
upon receiving this, the Processor
expedites the re-processing of the
message by making it visable in the queue
*/.
# Structs
ErrMessageExpired is returned when a message with an expired deadline is encountered and processing is abandoned.
Processor is the struct which orchestrates polling for messages as well as starting and feeding a configured number of workers in a pool.
No description provided by the author
# Interfaces
SQSClienter encapsulates all sqs methods a Processor will use.
# Type aliases
No description provided by the author
ProcessFunc is the signature of functions the user provides to process each message received off the queue.
ProcessResult is an enum used to signal success or failure when processing a message in a ProcessFunc.