-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (40 loc) · 977 Bytes
/
main.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
44
45
46
47
48
package main
import (
"fmt"
"github.com/adrianosela/sqs-backed-s3-processing/processor"
"github.com/aws/aws-sdk-go/aws/session"
"io"
"log"
"time"
)
// NOTE: replace with real values of region, account, and name
const sqsQueueURL = "https://sqs.<QUEUE_AWS_REGION>.amazonaws.com/<QUEUE_AWS_ACCOUNT>/<QUEUE_NAME>"
func main() {
p := processor.New(
session.Must(session.NewSession()), // will use default profile from ~/.aws profile
sqsQueueURL,
uint8(5), // n workers
uint8(1), // batch size
false) // delete sqs messages after processing
// stop in 5 seconds
go func() {
time.Sleep(time.Second * 5)
p.Stop()
}()
buff := make([]byte, 1024000)
err := p.Run(func(body io.ReadCloser) error {
defer body.Close()
n, err := body.Read(buff)
if err != nil {
if err == io.EOF {
return nil
}
return fmt.Errorf("Failed to read body: %s", err)
}
fmt.Println(string(buff[:n]))
return nil
})
if err != nil {
log.Fatal(err)
}
}