Search code examples
publish-subscribegoogle-cloud-pubsubapache-pulsaremqsocketcluster

Is there a Pub Sub service where publishers only send messages to a given topic if there are subscribers?


I'm looking for a scalable pub sub cluster where it's possible that publishers only send messages for a given topic to socketcluster if there are subscribers?

The reason being is that all of my publishers process millions of messages for many topics which for long periods won't have subscribers. So it's a huge waste computationally and price wise to send everything to the pub sub cluster.


Solution

  • PubSub is designed to decouple the subscribers and the publisher. So, your request is an anti-pattern of PubSub.

    Anyway, if you publish a message into PubSub and there isn't subscription (I said "subsciprions" not "subscriber"), the message is dropped. Your publishers can still check if a subscription exists on a topic before processing the messages. Subscribers check isn't possible.

    If there is one (or many) subscription, the message is send to it (if several subscription, the message is duplicated). The message are kept up to 7 days in the subscription, but you can reduce this duration according with your use case. by the way, when a subscriber will listen the subscription, it will be able to only receives and processes the relevant message, not the too old ones.