0
votes

I have 2 subscribers i.e. SUB1 & SUB2 for same Topic. Both the subscribers will pull the exact same message from Topic. How can I ensure that subscriber 'SUB2' starts pulling the message only after SUB1 has finished pulling the message from the topic. ...my PUB-SUB is from Google cloud Platform...

1

1 Answers

1
votes

There isn't really a good way to ensure that messages are delivered to one subscriber before they are delivered to the other subscriber if the messages are published to a single topic and the subscriptions are both on that topic. It also breaks the decoupling that is part of the pub/sub paradigm, where publishers don't have to be aware of subscribers and subscribers don't have to be aware of each other.

A good alternative is to have two topics. SUB1 would subscribe to the first topic. As part of its processing of a message, it publishes the message to the second topic. SUB2 would subscribe to the second topic. Therefore, you could guarantee that SUB2 processes messages only after SUB1 has processed it. These types of pipelines are a pretty typical use case for Cloud Pub/Sub, where each stage in the pipeline is responsible for producing the message that the next stage consumes.