Can I send batch message to AWS SNS
Asked Answered
F

4

5

I am developing an application in which I need to send multiple events to SNS. Is there any way to send all the events in batch or do I need to send/ publish using a for-loop (I'm using Java) one by one to the SNS.

Favorable answered 10/1, 2020 at 5:11 Comment(0)
R
6

The publish() API call only sends one message.

You will need to loop through your data and call publish() for each message.

Rumal answered 10/1, 2020 at 5:21 Comment(4)
Thanks @John. Is there any way I can validate if the publish is successful. I can see the "PublishResponse" returns only the message id. Can I check the status and validate?Favorable
Please check: Amazon SNS Topic Attributes for Message Delivery Status and Viewing Amazon CloudWatch Metrics docs.aws.amazon.com/sns/latest/dg/sns-topic-attributes.html or Logs for SMS Deliveries in the Amazon SNS Developer Guide docs.aws.amazon.com/sns/latest/dg/sms_stats_cloudwatch.htmlAbstract
@Favorable publish is when you send the message into SNS. If you get a MessageId back, then the publish succeeded, otherwise there could be no MessageId. Or, you might be referring to verifying delivery which is the asynchronous hand-off to the subscriber(s) on the other side of the SNS topic.Rademacher
@Michael-sqlbot You are right. I can always handle this on the receiver side as you said. If an SQS is subscribed to the SNS, I can verify if the SQS got the message.Favorable
H
7

SNS now supports publishing a batch of messages!

https://aws.amazon.com/about-aws/whats-new/2021/11/amazon-sns-supports-publishing-batches-messages-single-api-request/

Horned answered 19/11, 2021 at 2:15 Comment(0)
R
6

The publish() API call only sends one message.

You will need to loop through your data and call publish() for each message.

Rumal answered 10/1, 2020 at 5:21 Comment(4)
Thanks @John. Is there any way I can validate if the publish is successful. I can see the "PublishResponse" returns only the message id. Can I check the status and validate?Favorable
Please check: Amazon SNS Topic Attributes for Message Delivery Status and Viewing Amazon CloudWatch Metrics docs.aws.amazon.com/sns/latest/dg/sns-topic-attributes.html or Logs for SMS Deliveries in the Amazon SNS Developer Guide docs.aws.amazon.com/sns/latest/dg/sms_stats_cloudwatch.htmlAbstract
@Favorable publish is when you send the message into SNS. If you get a MessageId back, then the publish succeeded, otherwise there could be no MessageId. Or, you might be referring to verifying delivery which is the asynchronous hand-off to the subscriber(s) on the other side of the SNS topic.Rademacher
@Michael-sqlbot You are right. I can always handle this on the receiver side as you said. If an SQS is subscribed to the SNS, I can verify if the SQS got the message.Favorable
H
2

You can publish a batch of 10 messages in a single request now. It reduces the cost of API requests by 90%.

Link has the Java code references of bulk publishing.

Hotze answered 2/6, 2022 at 10:31 Comment(0)
A
0

If you need to publish multiple events, then I suggest to use EventBridge instead of SNS. It might cost a little more but We can pass around 10 events/ API call using EventBridge PutEvents API.

You can specify upto 5 targets as Lambda, SQS, etc. It can connect to all the services the SNS can pass on to and more.

Athapaskan answered 13/9, 2021 at 8:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.