Skip to content

Commit 9fc4376

Browse files
committed
add message group id if the publishing happens on a fifo queue
1 parent 5dd8f25 commit 9fc4376

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

publisher/sns/sns.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sns
33
import (
44
"context"
55
"encoding/json"
6+
"strings"
67

78
"github.com/aws/aws-sdk-go/aws"
89
"github.com/aws/aws-sdk-go/aws/request"
@@ -37,6 +38,8 @@ type Publisher struct {
3738
func (p *Publisher) Publish(ctx context.Context, msg interface{}) error {
3839
b, err := json.Marshal(msg)
3940

41+
defaultMessageGroupID := "default"
42+
4043
if err != nil {
4144
return err
4245
}
@@ -45,6 +48,10 @@ func (p *Publisher) Publish(ctx context.Context, msg interface{}) error {
4548
Message: aws.String(string(b)),
4649
TopicArn: &p.cfg.TopicArn,
4750
}
51+
// if the topic is a fifo topic, we need to set the message group id
52+
if strings.Contains(strings.ToLower(*input.TopicArn), "fifo") {
53+
input.MessageGroupId = &defaultMessageGroupID
54+
}
4855

4956
_, err = p.sns.PublishWithContext(ctx, input)
5057

0 commit comments

Comments
 (0)