Updated on 2024-08-12 GMT+08:00

Shell

  • Query the list of topics in current clusters.

    sh kafka-topics.sh --list --zookeeper <ZooKeeper cluster IP address:2181/kafka>

    sh kafka-topics.sh --list --bootstrap-server <Kafka cluster IP address:21007> --command-config config/client.properties

  • Query the details of a topic.

    sh kafka-topics.sh --describe --zookeeper <ZooKeeper cluster IP address:2181/kafka> --topic <Topic name>

    bin/kafka-topics.sh --describe --bootstrap-server <Kafka cluster IP address:21007> --command-config config/client.properties --topic <Topic name>

  • Delete a topic (this operation can be performed by an administrator).

    sh kafka-topics.sh --delete --zookeeper <ZooKeeperCluster IP address:2181/kafka> --topic <Topic name>

    sh kafka-topics.sh --delete --bootstrap-server <Kafka cluster IP address:21007>--command-config config/client.properties --topic <Topic name>

  • Create a topic (this operation can be performed by an administrator).

    sh kafka-topics.sh --create --zookeeper <ZooKeeperCluster IP address:2181/kafka> --partitions 6 --replication-factor 2 --topic <Topic name>

    sh kafka-topics.sh --create --bootstrap-server <Kafka cluster IP address:21007> --command-config config/client.properties --partitions 6 --replication-factor 2 --topic <Topic name>

  • Assign permissions to the Consumer (this operation is performed by an administrator).

    sh kafka-acls.sh --authorizer-properties zookeeper.connect=<ZooKeeper cluster IP address:2181/kafka > --add --allow-principal User:<User name> --consumer --topic <Topic name> --group <Consumer group name>

    sh kafka-acls.sh --bootstrap-server <Kafka cluster IP address:21007> --command-config config/client.properties --add --allow-principal User:<User name> --consumer --topic <Topic name> --group <Consumer group name>

  • Assign permissions to the Producer (this operation is performed by an administrator).

    sh kafka-acls.sh --authorizer-properties zookeeper.connect=<ZooKeeper cluster IP address:2181/kafka > --add --allow-principal User:<User name> --producer --topic <Topic name>

    sh kafka-acls.sh --bootstrap-server <Kafka cluster IP address:21007> --command-config config/client.properties --add --allow-principal User:<User name> --producer --topic <Topic name>

  • Produce messages (this operation requires the producer permission of the desired topic).

    sh kafka-console-producer.sh --broker-list <KafkaCluster IP address:21007> --topic <Topic name> --producer.config config/producer.properties

  • Consume data (the producer permission of the topic is required).

    sh kafka-console-consumer.sh --topic <Topic name> --bootstrap-server <KafkaCluster IP address:21007> --consumer.config config/consumer.properties