Skip to main content

2. 使用

创建一个topic

Let's create a topic named "test" with a single partition and only one replica:

bin/kafka-topics.sh --create --zookeeper 192.168.111.111:2181 --replication-factor 1 --partitions 1 --topic test

We can now see that topic if we run the list topic command:

> bin/kafka-topics.sh --list --zookeeper localhost:2181
test

生产者

bin/kafka-console-producer.sh --broker-list 192.168.111.111:9092 --topic test

消费者

bin/kafka-console-consumer.sh --bootstrap-server 192.168.111.111:9092 --topic test --from-beginning

创建

bin/kafka-topics.sh --create --zookeeper 192.168.111.111:2181,192.168.111.112:2181,192.168.111.113:2181 --replication-factor 3 --partitions 1 --topic asdasd

删除

bin/kafka-topics.sh --delete --zookeeper 192.168.111.111:2181,192.168.111.112:2181,192.168.111.113:2181 --topic asdasd

查看

bin/kafka-topics.sh --describe --zookeeper 192.168.111.111:2181,192.168.111.112:2181,192.168.111.113:2181 --topic asdasd