Read Avro messages from Kafka in terminal - kafka-avro-console-consumer alternative
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Avro is a popular data serialization system that is often used in Apache Kafka to ensure robust schema management and data integrity. Kafka's Avro messages typically utilize schemas, making it essential to have tooling that can both deserialize and display these messages directly from a Kafka topic for debugging and development purposes.
Here's how you can achieve reading Avro messages directly from a Kafka topic without using kafka-avro-console-consumer and explore some alternative methods and tools.
Using GenericRecord and SpecificRecord with KafkaAvroDeserializer
The Apache Kafka and Confluent Platform provide a tool known as kafka-avro-console-consumer, but one can also utilize programmable approaches such as using Kafka's own consumer API together with Avro deserializers.
Setup
- Dependencies: To begin, add dependencies for Apache Avro and the Kafka clients to your project. For Maven, the dependencies would look something like this:
- Kafka Consumer Configuration: Configure the Kafka consumer to use the Confluent
KafkaAvroDeserializer. This requires specifying the schema registry URL:
- Reading Messages: Create a Kafka consumer, subscribe to your topic, and read messages. Here's a simple example in Java:
Alternative Tools and Utilities
For those looking for alternatives similar to the functionality provided by kafka-avro-console-consumer, here are some options:
- Kafkacat with Avro Support: Kafkacat is a generic non-JVM producer and consumer for Kafka topics that, when built with Avro support, can consume Avro messages using schema information from Schema Registry.
- Kafka Tool: This is a GUI application that provides capabilities for managing and visualizing Kafka topics, and it can be configured to work with Avro.
Summary Table
| Feature | kafka-avro-console-consumer | Kafka Consumer API with Avro | Kafkacat | Kafka Tool GUI |
| Dependency on JVM | Yes | Yes | No | Yes |
| Require Confluent Platform | Yes | Optional | Optional | Optional |
| GUI Interface | No | No | No | Yes |
| Customizable Programming | No | Yes | Limited | Limited |
| Real-time Consumption | Yes | Yes | Yes | Yes |
Conclusion
Reading Avro messages from a Kafka topic in a terminal is achievable through various means, each with its benefits and drawbacks depending on your requirements and environment. Using Kafka's native APIs provides the most flexibility, while tools like Kafkacat offer simplicity and a quick setup for non-Java environments. For those who prefer a GUI, Kafka Tool provides an excellent visual approach.
This approach not only facilitates rapid development and debugging but also ensures that you can interact with your data in Kafka in a way that best fits your operational workflows.
Related reading
- Read from Kafka and write to hdfs in parquet
- Read input stream twice
- Read json from Kafka and write json to other Kafka topic
- read kafka message starting from a specific offset using high level API
- Read Kafka topic in a Spark batch job
- Read keys only from Kafka
- readinessProbe (k8s) for kafka statefulset causes bad deployment
- Reading a topic of kafka with react

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.