Home  >  Article  >  Java  >  Learn to use common Kafka commands and flexibly respond to various scenarios.

Learn to use common Kafka commands and flexibly respond to various scenarios.

王林
王林Original
2024-01-31 21:22:06675browse

Learn to use common Kafka commands and flexibly respond to various scenarios.

Essentials for learning Kafka: master common commands and easily cope with various scenarios

1. Create a Topic

bin/kafka-topics.sh --create --topic my-topic --partitions 3 --replication-factor 2

2. List Topic

bin/kafka-topics.sh --list

3. View Topic details

bin/kafka-topics.sh --describe --topic my-topic

4. Production message

bin/kafka-console-producer.sh --topic my-topic --message "Hello, Kafka!"

5. Consume messages

bin/kafka-console-consumer.sh --topic my-topic --from-beginning

6. Change the number of partitions

bin/kafka-topics.sh --alter --topic my-topic --partitions 5

7. Change Number of copies

bin/kafka-topics.sh --alter --topic my-topic --replication-factor 3

8. Delete Topic

bin/kafka-topics.sh --delete --topic my-topic

9. Create consumer group

bin/kafka-consumer-groups.sh --create --group my-group

10. List consumer groups

bin/kafka-consumer-groups.sh --list

11. View consumer group details

bin/kafka-consumer-groups.sh --describe --group my-group

12. Add consumers to consumers Group

bin/kafka-consumer-groups.sh --join --group my-group --topic my-topic

13. Remove the consumer from the consumer group

bin/kafka-consumer-groups.sh --leave --group my-group --topic my-topic

14. Delete the consumer group

bin/kafka-consumer-groups.sh --delete --group my-group

15. Get the offset of Topic

bin/kafka-run-class kafka.tools.GetOffsetShell --topic my-topic --group my-group

16. Set the offset of Topic

bin/kafka-run-class kafka.tools.OffsetResetTool --topic my-topic --group my-group --to-earliest

17. Monitor the Kafka cluster

bin/kafka-server-start.sh --daemon --console

18. Shut down the Kafka cluster

bin/kafka-server-stop.sh

19. Diagnose the Kafka cluster

bin/kafka-run-class kafka.tools.JmxTool --query "kafka.server:type=*,name=*,clientId=*"

20. Export the configuration of the Kafka cluster

bin/kafka-run-class kafka.tools.DumpLogSegments --print-data --source /tmp/kafka-logs

21. Import the configuration of the Kafka cluster

bin/kafka-run-class kafka.tools.LoadLogSegments --source /tmp/kafka-logs

22. Upgrade the Kafka cluster

bin/kafka-upgrade-kafka.sh --target-version 3.0.0

23. Downgrade the Kafka cluster

bin/kafka-downgrade-kafka.sh --target-version 2.8.0

The above is the detailed content of Learn to use common Kafka commands and flexibly respond to various scenarios.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn