繁体   English   中英

使用 Kafka 模式注册表 API 创建新的 avro 模式

[英]Create a new avro schema using Kafka schema-registry API

我正在尝试使用 kafka-schema-registery api 创建一个新模式。 我按照这篇文章中提到的步骤进行操作。 使用 Kafka 模式注册表 API 注册新的 avro 模式

我的 Avro 架构:

{
  "doc": "Sample schema to help you get started.",
  "fields": [
    {
      "doc": "The id of the order.",
      "name": "orderId",
      "type": "int"
    }
  ],
  "name": "sampleRecord",
  "namespace": "com.mycorp.mynamespace",
  "type": "record"
}

输入解析器:

 const inputSchemaJson = {
            "schema": JSON.stringify(inputSchema)
          }; 

下面是实现:

const https = require('https');

const options = {
                hostname: hostName,
                path: '/subjects/' + schemaName + '/versions',
                method: 'POST',
                json: true,
                body: inputSchemaJson,
                headers: {
                    'Content-Type': 'application/vnd.schemaregistry.v1+json',
                    'Authorization': 'Basic ' + authorizationHeader
                }
            };"

    const req = https.request(options, (res) => {
        let inputSchemaJson = '';

        console.log('Status Code:', res.statusCode);

        res.on('data', (chunk) => {
            inputSchemaJson += chunk;
        });

        res.on('end', () => {
            console.log('Body: ', JSON.parse(inputSchemaJson));
        });

    }).on("error", (err) => {
        console.log("Error: ", err.message);
    });

    req.write(inputSchemaJson);
    req.end();

但得到以下错误,任何建议。

 _http_outgoing.js:696
  throw new ERR_INVALID_ARG_TYPE('first argument',
        ^

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of Object

您发布的是 Javascript object。 您需要完全字符串化inputSchemaJson

暂无
暂无

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

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