Skip to content

Commit

Permalink
Merge pull request #759 from crankycookie/jkwon/add-sqs-fifo
Browse files Browse the repository at this point in the history
Adds the ability to use SQS FIFO queues.
  • Loading branch information
tidwall authored Dec 6, 2024
2 parents d445566 + d24fbd0 commit 459b3e6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/endpoint/sqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -145,3 +153,7 @@ func sqsRegionFromPlainURL(s string) string {
}
return ""
}

func isFifoQueue(s string) bool {
return strings.HasSuffix(s, ".fifo")
}

0 comments on commit 459b3e6

Please sign in to comment.