You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

861 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

  • 安装docker-compose.yml 文件所在目录下,运行以下命令启动 KafkaZookeeper
docker-compose up -d
  • 验证 Kafka 是否正常运行
docker ps

输出应显示 kafka 容器正在运行。

  • 创建测试主题
docker exec -it kafka kafka-topics.sh --create --topic test-topic --bootstrap-server localhost:9092 --partitions 1 --replication-factor 1
  • 列出主题
docker exec -it kafka kafka-topics.sh --list --bootstrap-server localhost:9092
  • 生产消息
docker exec -it kafka kafka-console-producer.sh --topic test-topic --bootstrap-server localhost:9092
  • 消费消息
docker exec -it kafka kafka-console-consumer.sh --topic test-topic --bootstrap-server localhost:9092 --from-beginning