1

Confluent schema registry currently support json schema. Does spring kafka provides support for json schema?

Avro with spring kafka works well using this config

spring:
  kafka:
    producer:
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
    consumer:
      group-id: template-cg
      auto-offset-reset: earliest
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
    properties:
      schema.registry.url: "http://localhost:8081"

But how to configure spring kafka to use json schema + confluent schema registry?

Timothy
  • 855
  • 1
  • 13
  • 29

1 Answers1

2

OK, as gary guides, this is not spring problem. Need to configure kafka like this.

spring:
  kafka:
    producer:
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: io.confluent.kafka.serializers.json.KafkaJsonSchemaSerializer
    consumer:
      group-id: template-cg
      auto-offset-reset: earliest
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: io.confluent.kafka.serializers.json.KafkaJsonSchemaDeserializer
    properties:
      schema.registry.url: http://localhost:8081

Dependency (gradle)

repositories {
    mavenCentral()
    maven { 
        url "https://packages.confluent.io/maven/"
    }
    maven { 
        url "https://jitpack.io"
    }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.kafka:spring-kafka'
    
    implementation 'io.confluent:kafka-json-schema-serializer:6.1.0'
    implementation 'com.github.everit-org.json-schema:org.everit.json.schema:1.12.2'
}
Timothy
  • 855
  • 1
  • 13
  • 29
  • thanks. I was looking for this. I understand that Kafka Schema registry plays a central role on this to allow schema evolution, which is great. However, is there a way to use json serializer without Kafka Schema registry? – Felipe Mar 25 '21 at 14:22