-
Notifications
You must be signed in to change notification settings - Fork 3
/
sqs.go
42 lines (35 loc) · 966 Bytes
/
sqs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
)
// Something good
type SQS struct {
cfg Config
sqsService *sqs.SQS
}
// Get the next batch of messages from the queue
func (instance SQS) NextMessages(queue string) ([]*sqs.Message, error) {
params := &sqs.ReceiveMessageInput{
QueueUrl: aws.String(instance.cfg.SQSURL),
MaxNumberOfMessages: aws.Int64(cfg.Connections),
WaitTimeSeconds: aws.Int64(instance.cfg.WaitTime),
}
resp, err := instance.sqsService.ReceiveMessage(params)
if err != nil {
return nil, err
}
return resp.Messages, nil
}
// Delete the message from the queue
func (instance SQS) Complete(queue, messageID string) (err error) {
params := &sqs.DeleteMessageInput{
QueueUrl: aws.String(instance.cfg.SQSURL),
ReceiptHandle: aws.String(messageID),
}
_, err = instance.sqsService.DeleteMessage(params)
if err != nil {
return err
}
return nil
}