When auto-topic-creation is disabled on Pulsar brokers (eg: using /bin/pulsar-admin namespaces set-auto-topic-creation public/default --disable
), it may be useful to check the existence of the topic and eventually create it if missing before starting a new consumersubscription.
Otherwise, a PulsarClientException$TopicDoesNotExistException
will be thrown
So, how to check if a topic exists and create it if necessary in Java ?
The below code shows how to create a topic if it does not exist.
Note that the code used here can be found on GitHub: Cheat Sheet for Apache Pulsar