0

我正在尝试使用 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
4

1 回答 1

0

您正在发布一个 Javascript 对象。您需要完全字符串化inputSchemaJson

于 2021-03-30T05:53:33.497 回答