Search code examples
jsonapache-kafkakafka-consumer-apikafka-producer-apiconfluent-schema-registry

How to consume and produce messages with JSON schemas through the Kafka Console Consumer and Producer


Is it possible to consume and produce messages with JSON schemas in Kafka, using kafka-console-consumer and kafka-console-producer respectively?


Solution

  • Confluent Platform 5.5 adds support for JSON Schema that also comes with kafka-json-schema-console-consumer and kafka-json-schema-console-producer.


    Consuming messages with JSON schema

    kafka-json-schema-console-consumer --topic myTopic --bootstrap-server localhost:9092
    

    Producing message with JSON schema

    kafka-json-schema-console-producer \
        --broker-list localhost:9092 \
        --topic myTopic \
        --property value.schema='{"type":"object","properties":{"f1":{"type":"string"}}}'