启动kafka
nohup /usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
nohup /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
创建topic
cd /usr/local/kafka
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test --config retention.ms=259200000
查看集群中的topic
bin/kafka-topics.sh --list --zookeeper localhost:2181
查看topic详细信息
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
改变主题分区数量
bin/kafka-topics.sh --zookeeper localhost:2181 --alter -partitions 8 -topic test
发送一些消息
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is another message
启动一个 consumer
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message
如果将上述命令在不同的终端中运行,那么现在就可以将消息输入到生产者终端中,并将它们在消费终端中显示出来。