Class JsonSchemaMessageReader
- All Implemented Interfaces:
Closeable,AutoCloseable,org.apache.kafka.common.Configurable,org.apache.kafka.tools.api.RecordReader
1. Send JSON Schema 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.JsonSchemaMessageReader \ --property schema.registry.url=http://localhost:8081 \ --property value.schema='{"type":"string"}'
In the shell, type in the following. "a" "b"
2. Send JSON Schema record as value. bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic t1 \ --line-reader io.confluent.kafka.formatter.JsonSchemaMessageReader \ --property schema.registry.url=http://localhost:8081 \ --property value.schema='{"type":"object","properties":{"f1":{"type":"string"}}}'
In the shell, type in the following. {"f1": "value1"}
3. Send JSON Schema string as key and JSON Schema record as value. bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic t1 \ --line-reader io.confluent.kafka.formatter.JsonSchemaMessageReader \ --property schema.registry.url=http://localhost:8081 \ --property parse.key=true \ --property key.schema='{"type":"string"}' \ --property value.schema='{"type":"object","properties":{"f1":{"type":"string"}}}' "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<com.fasterxml.jackson.databind.JsonNode>createSerializer(org.apache.kafka.common.serialization.Serializer keySerializer) protected SchemaProviderprotected com.fasterxml.jackson.databind.JsonNodereadFrom(String jsonString, ParsedSchema schema) Methods inherited from class io.confluent.kafka.formatter.SchemaMessageReader
close, configure, init, parseSchema, readRecords
-
Constructor Details
-
JsonSchemaMessageReader
public JsonSchemaMessageReader()Constructor needed by kafka console producer.
-
-
Method Details
-
createSerializer
protected SchemaMessageSerializer<com.fasterxml.jackson.databind.JsonNode> createSerializer(org.apache.kafka.common.serialization.Serializer keySerializer) - Specified by:
createSerializerin classSchemaMessageReader<com.fasterxml.jackson.databind.JsonNode>
-
getProvider
- Specified by:
getProviderin classSchemaMessageReader<com.fasterxml.jackson.databind.JsonNode>
-
readFrom
- Specified by:
readFromin classSchemaMessageReader<com.fasterxml.jackson.databind.JsonNode>
-