kafka基本操作
[ root@node001 opt] # kafka- topics. sh -- zookeeper node001: 2181 -- create -- replication- factor 3 -- partitions 1 -- topic t1
Created topic t1.
[ root@node001 opt] # kafka- topics. sh -- zookeeper node001: 2181 -- list
__consumer_offsets
demo01
t1
创建生产者 通过键盘输入到控制台上生成数据到某主题,下面举例主题为t1,之前已经创建。
[ root@node001 opt] # kafka- console- producer. sh -- broker- list node001: 9092 -- topic t1
> hello zhangsan
> hello lisi
> hello lilei
创建消费者 消费生产者生成的数据,例如主题t1,上面已经生产数据。
[ root@node001 opt] # kafka- console- consumer. sh -- bootstrap- server node001: 9092 -- from- beginning -- topic t1
hello zhangsan
hello lisi
hello lilei
查看主题详情
[ root@node001 opt] # kafka- topics. sh -- zookeeper node001: 2181 -- describe -- topic t1
Topic: t1 PartitionCount: 1 ReplicationFactor: 3 Configs:
Topic: t1 Partition: 0 Leader: 3 Replicas: 3 , 2 , 1 Isr: 3 , 2 , 1
删除主题
[ root@node001 opt] # kafka- topics. sh -- zookeeper node001: 2181 -- delete -- topic t1
Topic t1 is marked for deletion.
Note: This will have no impact if delete. topic. enable is not set to true .
查看主题列表 刚才将t1删除,现在查看主题就没有t1
[ root@node001 opt] # kafka- topics. sh -- zookeeper node001: 2181 -- list
__consumer_offsets
demo01