一、kafka生产者
1、控制台向topic生产数据
bin/kafka-console-producer.sh --broker-list 10.1.10.77:9092 --topic Thailand-Exception
{"carName":"1405","lineName":"36路","occurDate":1489740716280,"type":"breakDown"}
{"carName":"1405","lineName":"36路","occurDate":1490767331820,"type":"overSpeed"}
{"carName":"1405","lineName":"36路","occurDate":1490767348677,"type":"openCloseDoor"}
{"carName":"1405","lineName":"36路","occurDate":1490767316674,"type":"leaveLine"}
{"carName":"1405","lineName":"36路","occurDate":1490334108405,"type":"emergencyAlarm"}
{"carName":"1405","lineName":"36路","occurDate":1490334108405,"type":"overload"}
注:kafka集群生产消息与单点命令一样(在78上执行)
/home/liuwei/kafka_2.11-0.10.0.1/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
消费调度司机考勤数据(78上)
/home/liuwei/kafka_2.11-0.10.0.1/bin/kafka-console-producer.sh --broker-list 119.23.59.213:6667 --topic dispatchToApp
二、kafka消费者
1、控制台从topic消费数据(单点)(不加--from-beginning表示实时消费,否则表示从最开始消费)
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
2、新版本kakfa消费命令(单点)(带kafka服务器地址方式):
/usr/kafka/bin/kafka-console-consumer.sh --bootstrap-server 119.23.59.213:6667 --topic dispatchToApp --from-beginning
3、控制台从topic消费数据(集群)
/home/liuwei/kafka_2.11-0.10.0.1/bin/kafka-console-consumer.sh --zookeeper 10.1.254.83:2181,10.1.254.87:2182,10.1.254.88:2183 --topic test
tail -f 是linux下的命令 意思是动态监视文件尾部 tailf catalina.out
启动tomcat 监听日志 ./startup.sh ; tailf ../logs/catalina.out
三、其它命令
1、查看所有主题
bin/kafka-topics.sh --list --zookeeper localhost:2181
2、查看主题详情
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test
3、删除主题
bin/kafka-run-class.sh kafka.admin.TopicCommand –delete --topic test --zookeeper 10.1.10.77:2181