Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon SNS - is it possible to subscribe after publication and still get the message?

I know that generally SNS is a Pub-Sub mechanism, which "duplicates" a message to all the consumers that subscribed to the published topic.

Nevertheless, I saw a field "TTL" in the SNS API, which defines the expiration fo the message (in seconds since the message was created).

I was wondering: if I publish a message to topic T with expiration of 5 minutes, and after 2 minutes, a consumer subscribe to topic T - Will the consumer get the message?

like image 377
user1028741 Avatar asked Sep 15 '25 02:09

user1028741


2 Answers

Put simply, no.

Here is what I just tried

  1. Created a topic
  2. Subscribed one of my phone numbers
  3. Published a message with a 3600s TTL (got the message right away)
  4. Subscribed my second phone
  5. Published another message with a 3600s TTL

Both phones got the second message. The first message was not sent to the second phone (even though I subscribed it well within the first message TTL, but after its publication).

like image 163
F_SO_K Avatar answered Sep 17 '25 18:09

F_SO_K


No. You won't be receiving messages if you subscribe after the message is published to the SNS topic. This is because SNS doesn't retain any messages that are sent through it in the past.

Therefore once published a message, it will be delivered to the current subscribers, but not stored in a history for future subscribers by SNS.

like image 32
Ashan Avatar answered Sep 17 '25 20:09

Ashan