Writing the Kafka consumer output to a file

+1 vote

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
• 2,040 points
8,376 views

10 answers to this question.

+2 votes

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
• 13,350 points

Isn't that backward?  The question is about outputting consumer messages to a text file. 

kafka-console-producer.sh --broker-list localhost:9092 --topic Topic < abc.txt

That line is a producer loading the events from a file.

+1 vote

You can use a simple > for this:

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

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
+1 vote
$KAFKA_HOME/bin/connect-standalone.sh my-standalone.properties my-file.properties
answered Dec 7, 2018 by Ilegar
+1 vote
tail -n0 -F my_file.txt | kafka-console-producer.sh --broker-list localhost:9092 --topic my_topic
answered Dec 7, 2018 by anonymous
+1 vote
echo "message goes here" | kafka-console-consumer.sh --broker-list localhost:9092 --topic my_topic
answered Dec 7, 2018 by Raga
+1 vote
answered Dec 7, 2018 by Aslam
+1 vote

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
+1 vote
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic Multibrokerapplication > output.txt
answered Dec 7, 2018 by Samanth
+1 vote
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
• 10,760 points
366 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
• 4,580 points
110 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
• 10,760 points
1,637 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
• 10,760 points
223 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
• 10,760 points
3,551 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
• 10,760 points
440 views
+1 vote
11 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
18,191 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,280 points
1,318 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
• 13,350 points
2,941 views
+1 vote
12 answers