-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
50 lines (41 loc) · 1.3 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
package example
import(
"log"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/sqs"
SqsService "github.com/architsmat38/golang-aws-sqs/sqs"
"github.com/architsmat38/golang-aws-sqs/poller"
)
var (
accessKeyId string = "xxxxxxxxxxxxxxxxx"
secretKey string = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
region string = "xxxxxxxxxxxxxxxxx"
queueName string = "xxxxxxxxxxxxxxxxx"
)
func InitializePollerSQS() {
go poller.Start(poller.HandlerFunc(func(msg *sqs.Message) error {
var queueMessage string = aws.StringValue(msg.Body)
decoded, err := SqsService.Decode([]byte(queueMessage))
if err != nil {
return err
}
log.Println(string(decoded))
return nil
}))
}
func main() {
// Intiialize SQS client
SqsService.Initialize(
SqsService.New(queueName, region, accessKeyId, secretKey, ""),
SqsService.SetWaitSeconds(20),
)
// Initialize poller
InitializePollerSQS()
// Send
SqsService.Send(`{"id":1,"message":"Sending data"}`)
// Send in batches
var data []string = []string{`{"id":1,"message":"First message"}`, `{"id":2,"message":"Second message"}`}
SqsService.ProcessAndSendBatch(data)
time.Sleep(1*time.Minute)
}