I want to delete a kafka topic programatically and struggling a lot to make it work. Am using below maven dependency.
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.1.0</version>
</dependency>
Am using KafkaAdminClient. Here is my code,
AdminClient admin = KafkaAdminClient.create(getProperties(configuration.getKafkaConnectionString())));
private static Properties getProperties(String kafkaConnectionString) {
Properties config = new Properties();
config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaConnectionString);
return config;
}
Code to delete topic:
public void deleteTopic(final String... topicNames) {
admin.deleteTopics(Arrays.asList(topicNames));
log.info("Topics '{}' deleted.", topicNames);
}
I have delete.topic.enable=true property in server.properties for kafka. There are no exception. Not sure why its not working. Any help is appreciated.