Class AvroMessageReader
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.kafka.common.Configurable,org.apache.kafka.tools.api.RecordReader
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"}
-
Field Summary
Fields inherited from class io.confluent.kafka.formatter.SchemaMessageReader
KEY_SCHEMA, keySchema, VALUE_SCHEMA, valueSchema -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected SchemaMessageSerializer<Object>createSerializer(org.apache.kafka.common.serialization.Serializer keySerializer) protected SchemaProviderprotected ObjectreadFrom(String jsonString, ParsedSchema parsedSchema) Methods inherited from class io.confluent.kafka.formatter.SchemaMessageReader
close, configure, init, parseSchema, readRecords
-
Constructor Details
-
AvroMessageReader
public AvroMessageReader()Constructor needed by kafka console producer.
-
-
Method Details
-
createSerializer
protected SchemaMessageSerializer<Object> createSerializer(org.apache.kafka.common.serialization.Serializer keySerializer) - Specified by:
createSerializerin classSchemaMessageReader<Object>
-
getProvider
- Specified by:
getProviderin classSchemaMessageReader<Object>
-
readFrom
- Specified by:
readFromin classSchemaMessageReader<Object>
-