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

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

王林
Release: 2024-01-31 21:22:06
Original
746 people have browsed it

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
Copy after login

2. List Topic

bin/kafka-topics.sh --list
Copy after login

3. View Topic details

bin/kafka-topics.sh --describe --topic my-topic
Copy after login

4. Production message

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

5. Consume messages

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

6. Change the number of partitions

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

7. Change Number of copies

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

8. Delete Topic

bin/kafka-topics.sh --delete --topic my-topic
Copy after login

9. Create consumer group

bin/kafka-consumer-groups.sh --create --group my-group
Copy after login

10. List consumer groups

bin/kafka-consumer-groups.sh --list
Copy after login

11. View consumer group details

bin/kafka-consumer-groups.sh --describe --group my-group
Copy after login

12. Add consumers to consumers Group

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

13. Remove the consumer from the consumer group

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

14. Delete the consumer group

bin/kafka-consumer-groups.sh --delete --group my-group
Copy after login

15. Get the offset of Topic

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

16. Set the offset of Topic

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

17. Monitor the Kafka cluster

bin/kafka-server-start.sh --daemon --console
Copy after login

18. Shut down the Kafka cluster

bin/kafka-server-stop.sh
Copy after login

19. Diagnose the Kafka cluster

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

20. Export the configuration of the Kafka cluster

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

21. Import the configuration of the Kafka cluster

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

22. Upgrade the Kafka cluster

bin/kafka-upgrade-kafka.sh --target-version 3.0.0
Copy after login

23. Downgrade the Kafka cluster

bin/kafka-downgrade-kafka.sh --target-version 2.8.0
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template