Here are some common Apache Kafka admin commands, along with examples:
bin/kafka-topics.sh --list --zookeeper localhost:2181
: This command will list all the topics in the Kafka cluster.bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 3 --topic test
: This command will create a new topic called "test" with 3 partitions and 3 replicas.bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
: This command will show information about the "test" topic, such as the number of partitions, replicas, and the configuration for each partition.bin/kafka-topics.sh --delete --zookeeper localhost:2181 --topic test
: This command will delete the "test" topic.bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
: This command will start a producer console that you can use to send messages to the "test" topic.bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
: This command will start a consumer console that will read all the messages in the "test" topic from the beginning.bin/kafka-configs.sh --zookeeper localhost:2181 --alter --entity-type topics --entity-name test --add-config cleanup.policy=compact
: This command will add a new configuration property, "cleanup.policy=compact," to the "test" topic.
Here are a few more Apache Kafka admin commands that you might find useful:
bin/kafka-run-class.sh kafka.admin.ConsumerGroupCommand --bootstrap-server localhost:9092 --list
: This command will list all the consumer groups in the Kafka cluster.bin/kafka-run-class.sh kafka.admin.ConsumerGroupCommand --bootstrap-server localhost:9092 --describe --group group1
: This command will show information about the consumer group named "group1," including the current offset for each partition and the lag for each partition.bin/kafka-run-class.sh kafka.admin.ConsumerGroupCommand --bootstrap-server localhost:9092 --reset-offsets --group group1 --topic topic1 --to-offset 10 --execute
: This command will reset the offsets for the consumer group "group1" for the "topic1" topic to offset 10.bin/kafka-reassign-partitions.sh --zookeeper localhost:2181 --reassignment-json-file example.json --execute
: This command will execute a partition reassignment as specified in the JSON file "example.json."bin/kafka-preferred-replica-election.sh --zookeeper localhost:2181
: This command will trigger a preferred replica election for all topics in the Kafka cluster. This can be useful if you have a situation where a preferred replica is no longer available and you want to elect a new one.
Comments
Post a Comment