6.7基于命令行方式使用 Kafka
1、 创建主题
$ kafka-topics.sh --create \
--topic itcasttopic \
--partitions 3 \
--replication-factor 2 \
--zookeeper hadoop01:2181,hadoop02:2181,hadoop03:2181
2、向主题中发送消息数据
$ kafka-console-producer.sh \
--broker-list hadoop01:9092,hadoop02:9092,hadoop03:9092 \
--topic itcasttopic
--hello kafka
3、消费主题中的消息
$ kafka-console-consumer.sh \
--from-beginning --topic itcasttopic \
--bootstrap-server hadoop01:9092,hadoop02:9092,hadoop03:9092
Last modified: Friday, 29 October 2021, 12:42 PM