-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhook.go
43 lines (38 loc) · 1021 Bytes
/
hook.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
43
package main
import (
"fmt"
"log"
"sync"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
)
// Hooker outlines the interface that QueueHook should implement.
// It's here mainly to aid unittesting.
type Hooker interface {
Hook(*ProxySettings, *sync.WaitGroup)
Mover
}
// QueueHook Hooks to an SQS queue and Moves messages from it.
type QueueHook struct {
Client SQSClientor
Mover
}
// Hook starts listening from a source queue, and handling the messages
// that come through.
func (q *QueueHook) Hook(conf *ProxySettings, wg *sync.WaitGroup) error {
defer wg.Done()
readParams := sqs.ReceiveMessageInput{
MaxNumberOfMessages: aws.Int64(10),
QueueUrl: aws.String(conf.Src),
WaitTimeSeconds: aws.Int64(20),
}
for {
if err := q.Move(&readParams, conf.Dest); err != nil {
errIntro := fmt.Sprintf("Proxying from Queue %s has failed with error:", conf.Src)
log.Println(errIntro, err)
return err
}
time.Sleep(conf.Interval * time.Second)
}
}