kafka操作命令集
1、创建topic
命令:bin/kafka-topics.sh --create --zookeeper 192.168.1.188:2181 --replication-factor 1 --partitions 1 --topic yxcTest
成功返回:Create topic "yxcTest".
2、查看topic列表
命令:bin/kafka-topics.sh --list --zookeeper 192.168.188.1:12181
成功返回:yxcTest
3、发送接收消息
运行生产者脚本,然后通过控制台输入一些信息发送到服务器
命令:bin/kafka-console-producer.sh --broker-list 192.168.188.1:9092 --topic yxcTest
> This is a messager
>This is another messager
启动消费者,将收到的消息输出到标准输出
命令:bin/kafka-console-consumer.sh --bootstrap-server 192.168.188.1:9092 --from-beginning --topic yxcTest
<This is a messager
<This is another messager
4、查看topic的描述信息
命令:bin/kafka-topics.sh --describe --zookeeper 192.168.188.1:2181 --topic yxcTest
成功返回:Topic: yxcTest PartitionCount:1 ReplicationFactor:1 Configs: Topic: yxcTest Partition 0 Leader: 1 Replicas: 1 lsr: 1
5、删除topic
命令:bin/kafka-topics.sh --delete --zookeeper 192.168.188.1:2181 --topic yxcTest
成功返回:Topic yxcTest is marked for deletion. Note: This will have to impact if delete.topic.enable is not set to true.