Search code examples
google-cloud-platformgoogle-cloud-pubsubevent-driven

google cloud pub sub multiple subscriber for the same message with the same subscription


I am working on implementing event driven using GCP Pub/Sub.

I have a topic called orders, and that topic will have a subscription named orderPlacedSubscription I have two services that want to listen to all messages for this subscription and perform different actions, so I have paymentService and notificationService, the paymentService will listen to each message filtered by orderPlacedSubscription and process the payment as well as the notification service will listen to the same message and send a notification.

My question

  • does pub-sub support having two subscribers related to one subscription and both receive messages and acknowledge them separately?
  • In case if each subscriber can acknowledge the message separately without affecting the other subscriber, does google cloud pub-sub support retry for different subscribers in case of failure from one subscriber?

Solution

  • Yes, a subscription can have multiple subscriber clients.

    In a subscription workflow, if a message is not acknowledged by a subscriber, Pub/Sub will attempt to redeliver the outstanding message. In the process of redelivering the outstanding message, Pub/Sub holds back and tries not to deliver the outstanding message to any other subscriber on the same subscription. Once the outstanding message is acknowledged it can be delivered to other subscribers.

    You can refer subscription workflow and this documentation for more information.