dapr / dapr/components-contrib
Allow SNSSQS `MessageGroupId` to be set programatically via pubsub metadata
- Dominant language
- Go
- Stars
- 602
- Forks
- 580
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 6
Description
## Describe the feature
We have a business logic which requires to be able to take advantage of the `MessageGroupId` to be set programatically as we want to do FIFO parallel consumption but sequentially based on the same `MessageGroupId` groups.
I guess that adding a flag in the metadata and modifying something like `FifoMessageGroupId` key and checking if set, use it as a the result var for the function could make it.
We can do the PR work ;)
https://github.com/dapr/components-contrib/blob/f99604f063bb6756adbc98690fa9689d15718713/pubsub/aws/snssqs/snssqs.go#L371-L380
The code could look like this:
```go
func (s *snsSqs) getMessageGroupID(req *pubsub.PublishRequest) *string {
// if the request has provided a messageGroupID in the metadata, use it.
if req.Metadata["messageGroupID"] != "" {
fifoMessageGroupID := req.Metadata["messageGroupID"]
return &fifoMessageGroupID
}
if len(s.metadata.FifoMessageGroupID) > 0 {
return &s.metadata.FifoMessageGroupID
}
// each daprd, of a given PubSub, of a given publisher application publishes to a message group ID of its own.
// for example: for a daprd serving the SNS/SQS Pubsub component we generate a unique id -> A; that component serves on behalf
// of a given PubSub deployment name B, and component A publishes to SNS on behalf of a dapr application named C (effectively to topic C).
// therefore the created message group ID for publishing messages in the aforementioned setup is "A:B:C".
fifoMessageGroupID := fmt.Sprintf("%s:%s:%s", s.id, req.PubsubName, req.Topic)
return &fifoMessageGroupID
}
```
## Release Note
RELEASE NOTE: **ADD** SNSSQS `FifoMessagroupId` can be set programatically via pubsub req metadata.
Contributor guide
Research direction
Start in pubsub/aws/snssqs/snssqs.go around lines 371-380 and inspect how getMessageGroupID currently derives the FIFO group identifier from the component metadata. Verify the existing publish request metadata path, then confirm that the requested behavior works for programmatic MessageGroupId values while preserving the configured fallback and generated default.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, go
- Domain
- backend, distributed-systems
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100