-1

confluent-schema-registry javascript package can be used to serialize and de-serialize messages posted to Kafka Topic. Unfortunately, it only supports AVRO format. Is there a similar package that supports JSON serialization?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
alphanumeric
  • 17,967
  • 64
  • 244
  • 392

1 Answers1

2

If you go beyond the first page of the documentation, it shows more than just Avro.

const { SchemaType } = require('@kafkajs/confluent-schema-registry')

const schema = `
  {
    "definitions" : {
      "record:examples.Person" : {
        "type" : "object",
        "required" : [ "fullName" ],
        "additionalProperties" : false,
        "properties" : {
          "fullName" : {
            "type" : "string"
          }
        }
      }
    },
    "$ref" : "#/definitions/record:examples.Person"
  }
`
const { id } = await registry.register({ type: SchemaType.JSON, schema })

https://kafkajs.github.io/confluent-schema-registry/docs/usage#json-schema

Later in the page, it shows how to encode a payload with the schema ID, which can then be passed into your producer as a Buffer type

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245