Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k views
in Technique[技术] by (71.8m points)

Does cloud pubsub message ordering mean the subsequent message is not delivered until the previous one is acknowledged?

With Cloud Pubsub message ordering on a push subscription, if I publish two messages with the same ordering key, say Message #1 and Message #2, will Message #2 only be pushed after Message #1 is acknowledged? Or does ordering mean that Message #2 is guaranteed to be pushed after Message #1 by some infinitesimal time difference even without acknowledgement?

From testing using the publisher.py/subscriber.py tool scripts on github and commenting out the ack call, it seems that answer is that Message #2 is not delivered until Message #1 is acked. But that test was done using pull, so I'm not sure if push works differently.

However, the docs seem to suggest that Message #2 could be delivered before Message #1 is acked: https://cloud.google.com/pubsub/docs/ordering#receiving_messages_in_order

When the Pub/Sub service redelivers a message with an ordering key, the Pub/Sub service also redelivers every subsequent message with the same ordering key, including acknowledged messages. Acknowledge these messages again.

If there is strict ordering using acks, why would a previous message be redelivered after a subsequent message was ack'ed? Unless the redelivery was explicitly invoked using replay?

That difference is crucial when the subscription handler is a concurrent system.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For push subscription, you must acknowledge the first message in order to receive the next message on the same ordering key.

Cloud Pub/Sub offers at-least-once delivery. That means messages may be sent to subscribers multiple times, even if those messages have been acknowledged. With the consistent redelivery guarantee for ordering, when a message is redelivered, the entire sequence of subsequent messages for the same ordering key that were received after the redelivered message will also be redelivered.

For more information you can read the following blog post written on the feature by a Cloud Pub/Sub engineer: https://medium.com/google-cloud/google-cloud-pub-sub-ordered-delivery-1e4181f60bc8


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...