卡夫卡制作人读取数据文件 [英] Kafka producer to read data files
问题描述
我正在尝试循环加载数据文件(以检查统计信息),而不是在Kafka中加载标准输入.下载Kafka之后,我执行了以下步骤:
I am trying to load a data file in loop(to check stats) instead of standard input in Kafka. After downloading Kafka, I performed the following steps:
开始了动物园管理员:
bin/zookeeper-server-start.sh config/zookeeper.properties
启动服务器:
bin/kafka-server-start.sh config/server.properties
创建了一个名为测试"的主题:
Created a topic named "test":
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
禁止制作人
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
Test1
Test2
由消费者收听:
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
Test1
Test2
我想将数据文件传递给生产者,而不是标准输入,消费者可以直接看到它.还是有我可以读取数据文件的任何kafka生产者而不是控制台使用者.任何帮助将不胜感激.谢谢!
Instead of Standard input, I want to pass a data file to the Producer which can be seen directly by the Consumer. Or is there any kafka producer instead of console consumer using which I can read data files. Any help would really be appreciated. Thanks!
推荐答案
您可以通过cat读取数据文件并将其管道传输到kafka-console-producer.sh.
You can read data file via cat and pipeline it to kafka-console-producer.sh.
cat ${datafile} | ${kafka_home}/bin/kafka-console-producer.sh --broker-list ${brokerlist} --topic test
这篇关于卡夫卡制作人读取数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!