简体   繁体   中英

Ensure that second subscriber gets triggered after first subscriber has finished pulling in Google pub-sub topic

I have 2 subscribers ie 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...

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.

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