There are no APIs available to check the number of subscribers in a topic. (see my answer here )
You will need to implement server-side matching by storing the topic name and adding to the list of subscribers. After subscribing, add a new subscriber, check the counter (see, If it is within your preferred number), then activate the notification.
source share