How can check whether a message is present in a Pub/Sub topic without using a subscriber or listener?
There is no solution to know the content of a message other 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 if the subscription queue is empty, that means all the messages 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 the attribute of the message. Then you can create a PubSUb subscription with a filter on that attribute and to oversee the subscription as before.