Skip to content

Commit

Permalink
add message group id if the publishing happens on a fifo queue
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDHat committed Mar 24, 2022
1 parent 5dd8f25 commit 9fc4376
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions publisher/sns/sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sns
import (
"context"
"encoding/json"
"strings"

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

defaultMessageGroupID := "default"

if err != nil {
return err
}
Expand All @@ -45,6 +48,10 @@ func (p *Publisher) Publish(ctx context.Context, msg interface{}) error {
Message: aws.String(string(b)),
TopicArn: &p.cfg.TopicArn,
}
// if the topic is a fifo topic, we need to set the message group id
if strings.Contains(strings.ToLower(*input.TopicArn), "fifo") {
input.MessageGroupId = &defaultMessageGroupID
}

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

Expand Down

0 comments on commit 9fc4376

Please sign in to comment.