/
sqs.go
55 lines (50 loc) · 1.29 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sqs"
"github.com/ca-risken/common/pkg/logging"
"github.com/gassara-kys/go-sqs-poller/worker/v4"
"github.com/vikyd/zero"
)
type SQSConfig struct {
Debug string
AWSRegion string
SQSEndpoint string
WebsiteQueueName string
WebsiteQueueURL string
MaxNumberOfMessage int64
WaitTimeSecond int64
}
func newSQSConsumer(conf *SQSConfig) *worker.Worker {
if conf.Debug == "true" {
appLogger.Level(logging.DebugLevel)
}
var sqsClient *sqs.SQS
sess, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
appLogger.Fatalf("Failed to create a new session, %v", err)
}
if !zero.IsZeroVal(&conf.SQSEndpoint) {
sqsClient = sqs.New(sess, &aws.Config{
Region: &conf.AWSRegion,
Endpoint: &conf.SQSEndpoint,
})
} else {
sqsClient = sqs.New(sess, &aws.Config{
Region: &conf.AWSRegion,
})
}
return &worker.Worker{
Config: &worker.Config{
QueueName: conf.WebsiteQueueName,
QueueURL: conf.WebsiteQueueURL,
MaxNumberOfMessage: conf.MaxNumberOfMessage,
WaitTimeSecond: conf.WaitTimeSecond,
},
Log: appLogger,
SqsClient: sqsClient,
}
}