gpt4 book ai didi

python - 如何使用 confluence-kafka-python 删除主题

转载 作者:行者123 更新时间:2023-11-30 22:27:02 25 4
gpt4 key购买 nike

我正在使用 Kafka 使多个微服务相互通信。服务是用 Python 编写的,我使用 Confluence 库来处理 Kafka。在某些时候,我知道某些主题刚刚“结束”,这样我就可以自动清理它们。

有没有办法通过 Confluence 库删除“主题”?我找不到任何关于此的文档...

谢谢

最佳答案

您可以使用confluent Admin Api's to delete a topic

示例

获取 AdminClient 实例和主题列表

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))

关于python - 如何使用 confluence-kafka-python 删除主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47051351/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com