Skip to main content

kafka_admin_service

KAFKA管理类,提供用户创建、删除、列表查询、修改密码,提供主题创建、删除、列表查询,提供权限创建、删除、列表查询等基础管理功能。

安装

pip install kafka-admin-service

KafkaAdminService类方法

  • add_acl
  • change_password
  • create_topic
  • create_topic_and_topic_user
  • create_user
  • delete_acl
  • delete_all_topics
  • delete_all_users
  • delete_topic
  • delete_topic_user_acls
  • delete_user
  • get_acls
  • get_consumer_group_member_assignments
  • get_consumer_group_members
  • get_consumer_groups
  • get_kafka_log_dirs
  • get_kafka_version
  • get_topics
  • get_user_scrams
  • get_users
  • update_user
  • validate_user_password

返回值说明

由于KafkaAdminService在底层以“外部命令调用”的方式调用了kafka/bin/目录下的管理命令,所以返回值中大多会出现returncode/stdout/stderr等字段。其中returncode表示kafka管理命令执行后的退出值,stdout表示kafka管理命令执行后的输出,stderr表示kafka管理命令执行后的错误输出。

对于KAFKA服务器配置的要求

  1. 要求KAFKA集群使用了scram认证。
  2. 要求KAFKA依赖的zookeeper不使用认证。
  3. 要求应用运行时的当前目录是Kafka的根目录,或使用workspace指定kafka的根目录。
  4. 要求已创建正确的./config/scram.jaas文件。
  5. 要求已创建正确的./config/scram.client.properties文件。
  6. 要求应用服务能正常访问kafka服务器以及zookeeper服务器,所以一般情况下可以将管理应用安装在kafka节点机上。

./config/scram.jaas模板

KafkaServer {
   org.apache.kafka.common.security.scram.ScramLoginModule required
   username="admin"
   password="xxxxxxxx";
};

KafkaClient {
   org.apache.kafka.common.security.scram.ScramLoginModule required
   username="admin"
   password="xxxxxxxx";
};

./config/scram.client.properties模板

security.protocol=SASL_PLAINTEXT
sasl.mechanism=SCRAM-SHA-256

常用的类初始化配置:kafka_admin_service_config.yml

加载配置文件,传递给KafkaAdminService创建方法。

zookeeper: localhost:2181
bootstrap_server: localhost:9092
workspace: /apprun/kafka/
command_config_file: "/apprun/config/scram.client.properties"
default_kafka_opts: "-Djava.security.auth.login.config=/apprun/config/scram.jaas"
topic_partitions: 16
topic_replication_factor: 3
apikeys:
    xxxxxxx:
        appid: xxxx
        other-appinfo: xxx
    yyyyyyy:
        appid: yyyy
        other-appinfo: yyy

启动kafka-admin-server服务器

kafka-admin-server --no-daemon -c config.yml start

版本历史

v0.1.1

  • First Release.

v0.1.3

  • 优化脚本依赖程序的路径检查和提示。
  • 增加命令执行时间日志输出。

v0.1.7

  • 增加get_user_scrams方法,用于获取系统中用户的scram密码哈希信息。
  • 增加validate_user_password方法,用于检验用户密码是否正确。
  • 修正sdist在部分环境下安装时license文件缺失问题。
  • 更新文档。

v0.1.9

  • 修正命令参数填充不完整的问题。
  • 修正执行语句KAFKA_OPTS设置缺失的问题。

v0.2.1

  • 基于xmlrpc,引入kafka-admin-server。

v0.2.14

  • 增加get_consumer_group_member_assignments接口。
  • 增加get_consumer_group_members接口。
  • 增加get_consumer_groups接口。
  • 增加get_kafka_version接口。
  • 增加get_kafka_log_dirs接口。
  • 删除无效的接口导出。

v0.2.17

  • 增加get_user_configs接口。

v0.2.19

  • Doc update.

Release files for kafka-admin-service 0.2.19

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kafka-admin-service 0.2.19
File Size Uploaded
kafka_admin_service-0.2.19.tar.gz 11.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kafka-admin-service 0.2.19
File Interpreter ABI Platform
kafka_admin_service-0.2.19-py3-none-any.whl Python 3 none any Details

Total release size: 21.4 kB

Release files / kafka_admin_service-0.2.19.tar.gz

Download URL kafka_admin_service-0.2.19.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
48cb1c7a7450d0e1357127f635cd02e3e4d149cfb51fc706f6497b50a9b2da6a
BLAKE2b-256 checksum
How to use checksums
7eccaee4aa202e572caec61b1b1139ed8a713a49fc5359689cbca5cfcb6f3f22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release files / kafka_admin_service-0.2.19-py3-none-any.whl

Download URL kafka_admin_service-0.2.19-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a8ea0967724f001663d61f679a3a0791db2781307febedbef52dc6610d1ee82
BLAKE2b-256 checksum
How to use checksums
39bf31f6d6162f001d80275e530ff6ecbca41b356592d5109e98000c334b2d4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release history Release notifications | RSS feed

This release

0.2.19 This release

2 release files

0.2.18

2 release files

0.2.1

2 release files

0.1.9

2 release files

0.1.7

2 release files

0.1.3

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page