-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (48 loc) · 1.1 KB
/
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
49
50
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"go-sqs-receiver-demo/pkg/event"
"os"
"os/signal"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/sirupsen/logrus"
)
type myEventHandler struct {
logger *logrus.Logger
}
func (h myEventHandler) Handle(data interface{}) error {
message, ok := data.(*sqs.Message)
if !ok {
err := fmt.Errorf("Not an expected message")
h.logger.Error(err)
return err
}
fmt.Printf("Incoming Message: %s\n", *message.Body)
return nil
}
func main() {
logger := logrus.New()
queueName := "demo-queue"
region := "ap-southeast-1"
sess := session.Must(session.NewSession(&aws.Config{
Credentials: credentials.NewEnvCredentials(),
Region: ®ion,
}))
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, os.Kill)
eventHandler := myEventHandler{logger: logger}
sqsClient := sqs.New(sess)
receiver := event.NewSQSReceiverAdapter(
signalChan,
logger,
sqsClient,
queueName,
20,
30,
eventHandler,
)
receiver.Receive()
}