Is there a way to send messages to every client connected to the same subscriber on google pubsub?

3/27/2019

I have a topic with one subscription on pubsub. Each instance of my nodejs server listens to the subscription. Whenever there is a message, if it is delivered to any one of the server instances, the other instances do not receive it. Is there a way to make each instance receive the message?

Or will I have to create separate subscription for each instance?

-- Reetu
google-cloud-pubsub
kubernetes

1 Answer

3/28/2019

If you want every instance of a server to receive the message, then you need to use separate subscriptions. There are two forms of having multiple subscribers:

  1. Single subscription, multiple subscribers: this is load balancing, where messages are delivered to one of the subscribers (though duplicates can happen on occasion as Google Cloud Pub/Sub has at-least-once delivery). Use this mechanism when you need multiple subscribers to handle the throughput of messages.
  2. Multiple subscriptions, one subscriber per subscription: this is fan out, where messages are delivered to all of the subscribers because they each have their own subscription. Use this mechanism when you need each subscriber to receive and process every message.
-- Kamal Aboul-Hosn
Source: StackOverflow