@@ -4,9 +4,10 @@ import (
4
4
"C"
5
5
"errors"
6
6
"fmt"
7
+ "os"
8
+ "strconv"
7
9
"time"
8
10
"unsafe"
9
- "os"
10
11
11
12
"github.com/aws/aws-sdk-go/aws"
12
13
"github.com/aws/aws-sdk-go/aws/credentials"
@@ -24,7 +25,7 @@ import (
24
25
// integer representation for this plugin log level
25
26
// 0 - debug
26
27
// 1 - info
27
- // 2 - error
28
+ // 2 - error
28
29
var sqsOutLogLevel int
29
30
30
31
// MessageCounter is used for count the current SQS Batch messages
@@ -39,6 +40,7 @@ type sqsConfig struct {
39
40
mySQS * sqs.SQS
40
41
pluginTagAttribute string
41
42
proxyURL string
43
+ batchSize int
42
44
}
43
45
44
46
//export FLBPluginRegister
@@ -54,12 +56,14 @@ func FLBPluginInit(plugin unsafe.Pointer) int {
54
56
queueMessageGroupID := output .FLBPluginConfigKey (plugin , "QueueMessageGroupId" )
55
57
pluginTagAttribute := output .FLBPluginConfigKey (plugin , "PluginTagAttribute" )
56
58
proxyURL := output .FLBPluginConfigKey (plugin , "ProxyUrl" )
59
+ batchSizeString := output .FLBPluginConfigKey (plugin , "BatchSize" )
57
60
58
61
writeInfoLog (fmt .Sprintf ("QueueUrl is: %s" , queueURL ))
59
62
writeInfoLog (fmt .Sprintf ("QueueRegion is: %s" , queueRegion ))
60
63
writeInfoLog (fmt .Sprintf ("QueueMessageGroupId is: %s" , queueMessageGroupID ))
61
64
writeInfoLog (fmt .Sprintf ("pluginTagAttribute is: %s" , pluginTagAttribute ))
62
65
writeInfoLog (fmt .Sprintf ("ProxyUrl is: %s" , proxyURL ))
66
+ writeInfoLog (fmt .Sprintf ("BatchSize is: %s" , batchSizeString ))
63
67
64
68
if queueURL == "" {
65
69
writeErrorLog (errors .New ("QueueUrl configuration key is mandatory" ))
@@ -78,6 +82,12 @@ func FLBPluginInit(plugin unsafe.Pointer) int {
78
82
}
79
83
}
80
84
85
+ batchSize , err := strconv .Atoi (batchSizeString )
86
+ if err != nil || (0 > batchSize && batchSize > 10 ) {
87
+ writeErrorLog (errors .New ("BatchSize should be integer value between 1 and 10" ))
88
+ return output .FLB_ERROR
89
+ }
90
+
81
91
writeInfoLog ("retrieving aws credentials from environment variables" )
82
92
awsCredentials := credentials .NewEnvCredentials ()
83
93
var myAWSSession * session.Session
@@ -126,6 +136,7 @@ func FLBPluginInit(plugin unsafe.Pointer) int {
126
136
queueMessageGroupID : queueMessageGroupID ,
127
137
mySQS : sqs .New (myAWSSession ),
128
138
pluginTagAttribute : pluginTagAttribute ,
139
+ batchSize : batchSize ,
129
140
})
130
141
131
142
return output .FLB_OK
@@ -212,7 +223,7 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int
212
223
213
224
SqsRecords = append (SqsRecords , sqsRecord )
214
225
215
- if MessageCounter == 10 {
226
+ if MessageCounter == sqsConf . batchSize {
216
227
err := sendBatchToSqs (sqsConf , SqsRecords )
217
228
218
229
SqsRecords = nil
0 commit comments