public class AvroMessageReader extends SchemaMessageReader<Object>
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"}
KEY_SCHEMA, keySchema, VALUE_SCHEMA, valueSchema| Constructor and Description |
|---|
AvroMessageReader()
Constructor needed by kafka console producer.
|
| Modifier and Type | Method and Description |
|---|---|
protected SchemaMessageSerializer<Object> |
createSerializer(org.apache.kafka.common.serialization.Serializer keySerializer) |
protected SchemaProvider |
getProvider() |
protected Object |
readFrom(String jsonString,
ParsedSchema parsedSchema) |
close, configure, init, parseSchema, readRecordspublic AvroMessageReader()
protected SchemaMessageSerializer<Object> createSerializer(org.apache.kafka.common.serialization.Serializer keySerializer)
createSerializer in class SchemaMessageReader<Object>protected SchemaProvider getProvider()
getProvider in class SchemaMessageReader<Object>protected Object readFrom(String jsonString, ParsedSchema parsedSchema)
readFrom in class SchemaMessageReader<Object>Copyright © 2025 Confluent, Inc.. All rights reserved.