I have X micro-services each of them are them are publishing to the same pub/sub topic. The messages they publish contain the micro-service ID.
I am looking for a way to make sure that the pub/sub has finished servicing all the messages of a certain micro-service.
My current solution is to count all the messages that were published from the micro-service, and then count the messages that were served in the pub/sub topic (via cloud-function). There are some known issues with this approach, and I was wondering if there is a better way to know if the pub/sub does not contain messages from the specific micro-service?
There is no solution to know the content of a message than getting the message, opening it and reading it.
A better solution could be to use a separate topic for each type of message, and is the subscription queue is empty, that means all the message have been processed. If you need to count them, you can use the logs to track your message processing in Cloud FUnctions.
An alternative is to use a single PubSub topic and to add the ID in attribute of the message. Then you can create PubSUb subscription with a filter on that attribute and to oversee the subscription as before.
The bad side of that solution is that it's not compliant with Cloud Functions PubSub integration. You need to create an HTTP functions and a PubSub push subscription to be able to leverage the filter feature.
How to know if the pub/sub topic contains messages with specific content?