Class JsonSchemaMessageReader

java.lang.Object
io.confluent.kafka.formatter.SchemaMessageReader<com.fasterxml.jackson.databind.JsonNode>
io.confluent.kafka.formatter.json.JsonSchemaMessageReader
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.kafka.common.Configurable, org.apache.kafka.tools.api.RecordReader

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

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"}

  • Constructor Details

    • JsonSchemaMessageReader

      public JsonSchemaMessageReader()
      Constructor needed by kafka console producer.
  • Method Details