diff --git a/internal/endpoint/sqs.go b/internal/endpoint/sqs.go index e83a8711..c4ad42fc 100644 --- a/internal/endpoint/sqs.go +++ b/internal/endpoint/sqs.go @@ -6,6 +6,8 @@ import ( "sync" "time" + "github.com/tidwall/gjson" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" @@ -108,11 +110,17 @@ func (conn *SQSConn) Send(msg string) error { } queueURL := conn.generateSQSURL() - // Send message + // Create message sendParams := &sqs.SendMessageInput{ MessageBody: aws.String(msg), QueueUrl: aws.String(queueURL), } + if isFifoQueue(queueURL) { + key := gjson.Get(msg, "key") + id := gjson.Get(msg, "id") + keyValue := fmt.Sprintf("%s#%s", key.String(), id.String()) + sendParams.MessageGroupId = aws.String(keyValue) + } _, err := conn.svc.SendMessage(sendParams) if err != nil { fmt.Println(err) @@ -145,3 +153,7 @@ func sqsRegionFromPlainURL(s string) string { } return "" } + +func isFifoQueue(s string) bool { + return strings.HasSuffix(s, ".fifo") +}