繁体   English   中英

如何 JSON 序列化消息并使用 JSON 架构将其发布到 Kafka 主题

[英]How to JSON serialize message and post it to Kafka Topic with JSON Schema

confluent-schema-registry javascript package 可用于序列化和反序列化发布到 Kafka 主题的消息。 不幸的是,它只支持 AVRO 格式。 有没有类似的支持JSON序列化的package?

如果您的 go 超出了文档的第一页,它显示的不仅仅是 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

在页面后面,它展示了如何使用模式 ID 对有效负载进行编码,然后可以将其作为 Buffer 类型传递给您的生产者

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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