aspecto-io / sns-sqs-big-payload

Amazon SNS/SQS client library that enables sending and receiving messages with payload larger than 256KiB via Amazon S3.
Apache License 2.0
50 stars 17 forks source link

SNSProducer does not support MessageAttributes when publishing SNS messages #46

Open massa-man opened 2 years ago

massa-man commented 2 years ago

Thanks for making this library available, it is really useful. We are looking to implement this library in our project and came across a small issue. We currently have an events driven architecture, where we use a lot of SNS + SQS to route and fan out messages to different consumers. As multiple SQS queues might be subscribed to an SNS topic, we use MessageAttributes to filter out only the events the consumer needs to process and reduce the amount of lambda invocations.

We currently publish this way:

sns.publish({
  TopicArn: routerTopicArn,
  Message: JSON.stringify(event),
  MessageAttributes: {
    eventName: {
      DataType: 'String',
      StringValue: event.eventName || '',
    },
  },
});

And our SQS subscription filter policy to SNS looks something like this:

{
  "eventName": [
    "validation.create",
    "activity.process"
  ]
}

When looking closer at your SNSProducer we noticed you expose a sendJSON method that creates the JSON string and publishes the message, but does not allow us to pass any other inputs to the core SNS publish method, in our case MessageAttributes.

Would it be possible to add this support? I am happy to provide a patch for this is you accept contributions.

ragaak commented 2 years ago

can anyone please take a look at the open merge request?