Kafka integration with Hadoop helps move data from real-time streams into big storage for analysis. It connects fast data sources with Hadoop's storage and processing power.
Kafka integration with Hadoop
kafka-console-consumer --bootstrap-server <kafka-broker> --topic <topic-name> --from-beginning | hadoop fs -appendToFile - <hdfs-path>
This command reads messages from Kafka and writes them into Hadoop's HDFS.
You can also use tools like Apache Flume or Apache NiFi for more complex integration.
kafka-console-consumer --bootstrap-server localhost:9092 --topic sensor-data --from-beginning | hadoop fs -appendToFile - /user/hadoop/sensor-data/data.txtflume-ng agent -n agent1 -c conf -f flume-kafka-hdfs.conf
This script reads all messages from Kafka topic 'test-topic' and appends them as a file in HDFS. Then it lists and shows the saved data.
# This example uses Kafka console consumer and Hadoop fs commands # Step 1: Start Kafka consumer to read from topic 'test-topic' # Step 2: Pipe output to HDFS file '/user/hadoop/test-topic-data/data.txt' kafka-console-consumer --bootstrap-server localhost:9092 --topic test-topic --from-beginning | hadoop fs -appendToFile - /user/hadoop/test-topic-data/data.txt # After running, check data in HDFS hadoop fs -ls /user/hadoop/test-topic-data hadoop fs -cat /user/hadoop/test-topic-data/data.txt
Make sure Kafka and Hadoop services are running before integration.
Data formats should be compatible between Kafka messages and Hadoop storage.
For large-scale or continuous data, use tools like Apache Flume or NiFi instead of simple console commands.
Kafka integration with Hadoop moves streaming data into big storage for analysis.
Use simple commands for small data or tools like Flume for production pipelines.
Check data in HDFS after transfer to confirm successful integration.
Practice
Solution
Step 1: Understand Kafka and Hadoop roles
Kafka streams data in real-time, Hadoop stores large data for analysis.Step 2: Identify integration purpose
Integration moves streaming data from Kafka into Hadoop for big data processing.Final Answer:
To move streaming data into Hadoop storage for analysis -> Option AQuick Check:
Kafka streams + Hadoop stores = Integration purpose [OK]
- Thinking Kafka replaces Hadoop storage
- Assuming Kafka runs ML models
- Believing visualization happens directly in Kafka
sensor_data?Solution
Step 1: Identify Kafka consumer command
The command to read messages iskafka-console-consumerwith topic and server options.Step 2: Match command to options
kafka-console-consumer --topic sensor_data --bootstrap-server localhost:9092 uses correct consumer command and parameters for topicsensor_data.Final Answer:
kafka-console-consumer --topic sensor_data --bootstrap-server localhost:9092 -> Option CQuick Check:
Consumer command with topic and server [OK]
- Using producer command instead of consumer
- Confusing Hadoop fs commands with Kafka
- Using outdated or incorrect Kafka class commands
agent.sources = kafkaSource agent.channels = memoryChannel agent.sinks = hdfsSink agent.sources.kafkaSource.type = org.apache.flume.source.kafka.KafkaSource agent.sources.kafkaSource.kafka.bootstrap.servers = localhost:9092 agent.sources.kafkaSource.kafka.topics = sensor_data agent.channels.memoryChannel.type = memory agent.sinks.hdfsSink.type = hdfs agent.sinks.hdfsSink.hdfs.path = /data/sensor agent.sinks.hdfsSink.channel = memoryChannel
What will be the HDFS directory where Kafka data is stored?
Solution
Step 1: Locate HDFS path in sink configuration
The sinkhdfsSinkhashdfs.path = /data/sensor.Step 2: Confirm data storage directory
Kafka data consumed by Flume will be stored in/data/sensoron HDFS.Final Answer:
/data/sensor -> Option AQuick Check:
HDFS sink path = /data/sensor [OK]
hdfs.path in sink config for storage location [OK]- Confusing Kafka topic name with HDFS path
- Assuming default Flume user directory
- Ignoring channel configuration
Solution
Step 1: Check common config errors
Misspelling Kafka topic means Flume reads no data from Kafka.Step 2: Evaluate options
Correct HDFS path and channel type do not cause no data; missing agent name causes startup error, not silent failure.Final Answer:
The Kafka topic name inkafka.topicsis misspelled -> Option DQuick Check:
Wrong topic name = no data read [OK]
- Assuming HDFS path causes no data
- Changing channel type incorrectly
- Ignoring agent name errors
Solution
Step 1: Identify streaming ingestion method
Flume with KafkaSource is designed to stream Kafka data into HDFS efficiently.Step 2: Choose batch analysis tool
Hadoop MapReduce runs batch jobs on HDFS data daily, fitting the requirement.Final Answer:
Use KafkaSource in Flume to ingest data into HDFS, then run Hadoop MapReduce daily -> Option BQuick Check:
Flume + KafkaSource + HDFS + MapReduce = correct pipeline [OK]
- Using Kafka producer to write directly to HDFS (not supported)
- Confusing streaming with batch tools
- Manual upload instead of automated pipeline
Ready to prove it?
Pass the test and this pattern moves unknown
