Hi
I am trying to run GCP PubSub emulator on my local machine. If I want multiple clients to receive all the messages for the same topic_path (subscription_path), is there any way to do so? Currently, if multiple clients subscribe to same topic_path, the messages get delivered only to one of the clients. Sending messsages only to one of the clients seems to be in line with the documentation. But I am surprised why is this the case? Is it not possible in real life that multiple clients may want to subscribe to the same topic/subscription?
Did you create a subscription for each of the clients ?
Since all of my clients try to subscribe for the same topic (subscription path ), the subscription gets created only when the first time a client calls the below line of code
subscriber.create_subscription(subscription_path, topic_path)
For rest of the clients, the above line fails which I catch in try-except block.
After this, the client calls the below line of code:
subscription = subscriber.subscribe(subscription_path, callback)
This is successful for all the clients but only one of them receive the published message.
Complete code:
sample_code.txt
@kudhru that's how it works: if your processes all share the same subscription, then the messages will be distributed among them. If each of your processes has their own subscription, they will receive a copy of each message. See https://cloud.google.com/pubsub/architecture#the_basics_of_a_publishsubscribe_service
(Closing for now)
Oh!
Now, I understand. Basically, Google PubSub has an extra layer of 'subscription' between 'topic' and 'subscribers'. So, multiple subscribers can still get the messages of the same topic but via different subscriptions. Makes sense!
thanks a lot @jonparrott @Spriithy
Happy to help (this was a bit surprising to me at first, too). :)
Most helpful comment
@kudhru that's how it works: if your processes all share the same subscription, then the messages will be distributed among them. If each of your processes has their own subscription, they will receive a copy of each message. See https://cloud.google.com/pubsub/architecture#the_basics_of_a_publishsubscribe_service
(Closing for now)