I am using Kafka to make multiple micro services communicate with each other. Services are written in Python, and I use Confluent library to handle Kafka. At some point, I know that some Topics are just 'over', so that I could clean them automatically.
Is there a way to delete "Topics" thanks to Confluent library ? I cannot find any documentation on this...
Thanks
You can use the confluent Admin Api's to delete a topic
Example
Takes an AdminClient instance and a list of topics
def example_delete_topics(a, topics):
""" delete topics """
# Call delete_topics to asynchronously delete topics, a future is returned.
# By default this operation on the broker returns immediately while
# topics are deleted in the background. But here we give it some time (30s)
# to propagate in the cluster before returning.
#
# Returns a dict of <topic,future>.
fs = a.delete_topics(topics, operation_timeout=30)
# Wait for operation to finish.
for topic, f in fs.items():
try:
f.result() # The result itself is None
print("Topic {} deleted".format(topic))
except Exception as e:
print("Failed to delete topic {}: {}".format(topic, e))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With