简体   繁体   English

如何描述主题kafka的配置?

[英]How to describe configuration of topic kafka?

I want to describe the configuration of one topic.我想描述一个主题的配置。 I developed a script using confluent-kafka-python librairie (version 1.5.0) and my version of python is 2.7.我使用 confluent-kafka-python librairie(版本 1.5.0)开发了一个脚本,我的 python 版本是 2.7。 My final goal is to be able to change the retention time to my topic (retention.ms), but for this I need to extract all configuration of my topic and change just what I want and leaving the others as they have been defined.我的最终目标是能够将保留时间更改为我的主题 (retention.ms),但为此,我需要提取我的主题的所有配置并更改我想要的内容,并保留其他已定义的内容。

My script:我的脚本:

def describe_topic(admin_client, topic):

resources = [ConfigResource(confluent_kafka.admin.RESOURCE_TOPIC, topic)]
fs = admin_client.describe_configs(resources)
for resource, f in fs.items():
    remote_config = f.result()
    print(remote_config)
    return resource, remote_config

But I have this error :但我有这个错误:

Error错误
File "kafka.py", line 192, in describe_topic文件“kafka.py”,第 192 行,在 describe_topic 中
resources = [ConfigResource(confluent_kafka.admin.RESOURCE_TOPIC, topic)]资源 = [配置资源(confluent_kafka.admin.RESOURCE_TOPIC,主题)]
File "environment/mamba-6Od8R-HF-py2.7/lib/python2.7/site-packages/kafka/admin/config_resource.py", line 33, in init文件“environment/mamba-6Od8R-HF-py2.7/lib/python2.7/site-packages/kafka/admin/config_resource.py”,第 33 行,在init 中
resource_type = ConfigResourceType[str(resource_type).upper()] # pylint: disable-msg=unsubscriptable-object resource_type = ConfigResourceType[str(resource_type).upper()] # pylint: disable-msg=unsubscriptable-object
File "/product/tedhdev/environment/mamba-6Od8R-HF-py2.7/lib/python2.7/site-packages/enum/ init .py", line 394, in getitem文件“/product/tedhdev/environment/mamba-6Od8R-HF-py2.7/lib/python2.7/site-packages/enum/初始化的.py”,线路394,在的GetItem
return cls.返回 cls。 member_map [name] member_map [名称]
KeyError: '2'\\密钥错误:'2'\\

Can someone help me?有人能帮我吗? Thanks a lot非常感谢

import kafka
from kafka.admin import KafkaAdminClient, ConfigResource, ConfigResourceType

client_conn = kafka.KafkaAdminClient(bootstrap_servers="localhost:9092")
print(client_conn.describe_configs(config_resources=[ConfigResource(ConfigResourceType.TOPIC, "topic")]))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM