简体   繁体   中英

Spring Kafka + Json + Schema Registry Confluent

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM