As per the GCP documentation, messages are retained as below:
Question - Lets say we have single subscriber. Pub/Sub Topic is set to 2 days retention. In this case, does pub/sub retains message for 2 days after it is being read or discards immediately and not available for reply if needed within 2 days? Little confused with the statement "By default, Pub/Sub discards a message from a subscription as soon as the message is acknowledged".
Retention time is measured purely in terms of publish time. So two days of retention means two days since the time of publish. If you want to seek to redeliver the message after it has been acknowledged by the subscriber, Then two things must be true:
So in the case where topic retention is enabled and set to two days, then if the message has been delivered and acknowledged by a subscriber for the subscription, then it is possible to replay the message via a seek within two days of the original publish time.