使用 Kafka 模式注册表创建新的 avro 模式 API
Create a new avro schema using Kafka schema-registry API
我正在尝试使用 kafka-schema-registery api 创建一个新模式。我按照 post 中提到的步骤进行操作。
我的 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
错误是自我描述的
argument must be of type string ... Received an instance of Object
您正在 POST-ing 一个 Javascript 对象。您需要完全字符串化 inputSchemaJson
我正在尝试使用 kafka-schema-registery api 创建一个新模式。我按照 post 中提到的步骤进行操作。
我的 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
错误是自我描述的
argument must be of type string ... Received an instance of Object
您正在 POST-ing 一个 Javascript 对象。您需要完全字符串化 inputSchemaJson