简体   繁体   中英

GCP Pub/Sub Messages sent to topic that existed before the subscription was created

In the GCP pub/sub documentation it says that messages sent to the topic before a subscription was created will not be sent to the subscription. I'm wondering if you have a topic that has no subscriptions bound but messages are being published to it and then a subscription is bound will the messages in the topic be sent to the newly bound subscription?

A second scenario would a topic with multiple subscriptions and messages are flowing through but say a new subscription is bound to that topic at 1:00 am. Is that subscription not eligble to receive any messages that were sent before 1:00 am?

Documentation I am referring to. https://cloud.google.com/pubsub/docs/subscriber

This is the statement I am referring to in particular

A message published before a given subscription was created will usually not be delivered for that subscription. Thus, a message published to a topic that has no subscription will not be delivered to any subscriber.

Note that it doesn't say "messages sent to the topic before a subscription was created will not be sent to the subscription," it says "A message published before a given subscription was created will usually not be delivered for that subscription." In other words, there are no guarantees one way or the other about what happens with messages published before.

The only guarantee that Cloud Pub/Sub makes is that messages published after the successful creation of the subscription will definitely be delivered to subscribers for that subscription. So in your first scenario, messages published after the subscription is created will be sent and ones published before may or may not. In the second scenario, messages published before 1am may or may not be delivered to subscribers for the subscription.

As already explained in the other answer, messages sent to a topic before a subscription existed won't be delivered to the subscription, in general.

However, it's possible to "force" this by resetting the backlog of a newly created subscription to a previous point in time. The point in time must within the retention period of the topic, assuming message retention was enabled for the topic.

I'm wondering if you have a topic that has no subscriptions bound but messages are being published to it and then a subscription is bound will the messages in the topic be sent to the newly bound subscription?

Let's say you have a topic topic1 and message retention was enabled for it. You can use the gcloud pubsub subscriptions seek command to "replay" older messages (up to topic1 's retention period) to the (newly created) subcription1 :

gcloud pubsub subscriptions seek test-subscription \
  --time="$(date --date="10 days ago")"

Please note that the date subcommand won't work on macOS but you could install and use gdate instead ( brew install gdate ).

The use case of accessing historical topic data for new use-cases was described in a greater detail in this article .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM