Writing the Kafka consumer output to a file

0 votes

I want to write the messages which I am consuming using console consumer to a text file which I can keep for the future reference. Can anyone tell me how to do that?

Jul 9, 2018 in Apache Kafka by coldcode
• 1,980 points
3,332 views

10 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+1 vote

Use the pipe operator when you are running the console consumer. It will log all the messages which are getting consumed, to a file.

kafka-console-producer.sh --broker-list localhost:9092 --topic Topic < abc.txt
answered Jul 9, 2018 by Shubham
• 12,270 points
0 votes

You can use a simple > for this:

kafka-console-consumer > file.txt
answered Dec 7, 2018 by Sachin
+1 vote

System.out.println(String.valueOf(output.offset()) + ": " + new String(bytes, "UTF-8"));
outputmessage += new String(bytes, "UTF-8")+"\n";

writeDataToFile(outputmessage);

answered Dec 7, 2018 by Harsh
Can you plz ping me the full code , Im in learning of kafka
0 votes
$KAFKA_HOME/bin/connect-standalone.sh my-standalone.properties my-file.properties
answered Dec 7, 2018 by Ilegar
0 votes
tail -n0 -F my_file.txt | kafka-console-producer.sh --broker-list localhost:9092 --topic my_topic
answered Dec 7, 2018 by anonymous
0 votes
echo "message goes here" | kafka-console-consumer.sh --broker-list localhost:9092 --topic my_topic
answered Dec 7, 2018 by Raga
0 votes
answered Dec 7, 2018 by Aslam
0 votes

You can create topic and then cat it to output file:

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 
-partitions 1 --topic topic-name
answered Dec 7, 2018 by Logita
0 votes
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic Multibrokerapplication > output.txt
answered Dec 7, 2018 by Samanth
0 votes
answered Dec 7, 2018 by Renku

Related Questions In Apache Kafka

0 votes
1 answer

Is there any change in consumer offsets if a new partition(s) is added to a Kafka topic?

Yes, it stays the same. An offset is ...READ MORE

answered Jul 9, 2018 in Apache Kafka by nitinrawat895
• 9,070 points
140 views
0 votes
1 answer

Explain to me the functionality of Kafka in a Big-Data Cluster

Let me explain to you about Apache ...READ MORE

answered Apr 30 in Apache Kafka by ravikiran
• 1,540 points
16 views
0 votes
1 answer

What is the optimum number of producers to create in Kafka?

In general, a single producer for all ...READ MORE

answered Jul 10, 2018 in Apache Kafka by nitinrawat895
• 9,070 points
873 views
0 votes
1 answer

How to delete a topic in Kafka 0.8.1.1?

Deleting topic isn't always working in 0.8.1.1 Deletion ...READ MORE

answered Sep 4, 2018 in Apache Kafka by nitinrawat895
• 9,070 points
69 views
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 9,070 points
1,670 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 9,070 points
130 views
0 votes
10 answers

hadoop fs -put command?

copy command can be used to copy files ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Sujay
8,121 views
0 votes
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,260 points
570 views
0 votes
1 answer

How to reset the offset of messages consumed from Kafka?

The reset option only prints the result ...READ MORE

answered Jul 9, 2018 in Apache Kafka by Shubham
• 12,270 points
1,215 views
0 votes
11 answers

How can I delete all the messages from a Kafka topic?

To purge the Kafka topic, you need ...READ MORE

answered Jul 9, 2018 in Apache Kafka by Shubham
• 12,270 points
16,013 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.