# Kafka

# 一、快速指南

官方快速指南 (opens new window)

# 1.1 启动kafka

# Start the ZooKeeper service
# Note: Soon, ZooKeeper will no longer be required by Apache Kafka.
$ bin/zookeeper-server-start.sh config/zookeeper.properties
1
2
3
# Start the Kafka broker service
$ bin/kafka-server-start.sh config/server.properties
1
2

# 1.2 创建topic

$ bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092
1

# 1.3 创造消息

$ bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
This is my first event
This is my second event
1
2
3

# 1.4 消费消息

$ bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
This is my first event
This is my second event
1
2
3

# 1.5 删除数据

停掉服务,然后清除数据。

$ rm -rf /tmp/kafka-logs /tmp/zookeeper
1

# 1.6 删除某个topic的数据

bin/kafka-topics.sh --delete --topic bin_log_coupon --zookeeper localhost:2181
1
更新时间: 3/3/2021, 6:34:14 PM