Class AvroMessageReader

java.lang.Object
io.confluent.kafka.formatter.SchemaMessageReader<Object>
io.confluent.kafka.formatter.AvroMessageReader
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.kafka.common.Configurable, org.apache.kafka.tools.api.RecordReader

public class AvroMessageReader extends SchemaMessageReader<Object>
Example To use AvroMessageReader, first make sure that Zookeeper, Kafka and schema registry server are all started. Second, make sure the jar for AvroMessageReader and its dependencies are included in the classpath of kafka-console-producer.sh. Then run the following command.

1. Send Avro string as value. (make sure there is no space in the schema string) bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic t1 \ --line-reader io.confluent.kafka.formatter.AvroMessageReader \ --property schema.registry.url=http://localhost:8081 \ --property value.schema='{"type":"string"}'

In the shell, type in the following. "a" "b"

2. Send Avro record as value. bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic t1 \ --line-reader io.confluent.kafka.formatter.AvroMessageReader \ --property schema.registry.url=http://localhost:8081 \ --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}'

In the shell, type in the following. {"f1": "value1"}

3. Send Avro string as key and Avro record as value. bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic t1 \ --line-reader io.confluent.kafka.formatter.AvroMessageReader \ --property schema.registry.url=http://localhost:8081 \ --property parse.key=true \ --property key.schema='{"type":"string"}' \ --property value.schema='{"type":"record","name":"myrecord","fields":[{"name":"f1","type":"string"}]}'

In the shell, type in the following. "key1" \t {"f1": "value1"}