在本地部署一个用于测试的 Kafka,步骤如下。以 2.3.0 版本为例,官方文档:https://kafka.apache.org/23/documentation.html#quickstart

部署启动

  1. 下载安装包,wget https://archive.apache.org/dist/kafka/2.3.0/kafka_2.12-2.3.0.tgz
  2. 找一个目录,解压。tar -xvzf kafka_2.12-2.3.0.tgz
  3. 启动 ZooKeeper。bin/zookeeper-server-start.sh config/zookeeper.properties
  4. 启动 Kafka Server。bin/kafka-server-start.sh config/server.properties

测试

  1. 创建一个 topic。bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test
  2. 查看 topic。bin/kafka-topics.sh --list --bootstrap-server localhost:9092
  3. 发送消息。
> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is another message
  1. 消费消息。
> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message