You can use PulsarAdmin to check for active subscriptions. Nevertheless I think that the requirement is problematic:
• What if theres is a consumer, but is not processing messages, or processing messages at a very low rate. It’s logically equal to disconnected consumer
• What if you detect the consumer, start to publish, and then the consumer gets disconnected (like network error). There are still messages that will be written to the topic, because there will be a delay between the check and stopping of producing. There is no “immediate” detection possible as far as I know