使用Kafka模式注册API注册新的Avro模式 [英] Register a new avro schema using Kafka schema-registry API
本文介绍了使用Kafka模式注册API注册新的Avro模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 kafka-schema-registery
API创建新的 schema
.下面是实现:
I am trying to create a new schema
using the kafka-schema-registery
api. below is the implementation :
let value = JSON.stringify(avroSchema);
let type= {"schema" : value};
fetch(`${process.env.SCHEMA_REGISTRY_URL}/subjects/${topic}/versions`,
{
body : type,
method : 'POST',
headers :{ 'Content-Type': 'application/vnd.schemaregistry.v1+json,
application/vnd.schemaregistry+json, application/json',
'Accept' : 'application/vnd.schemaregistry.v1+json,
application/vnd.schemaregistry+json, application/json'
}
})
.then(res=>res.json())
.then((result)=>{
console.log('result is ', result);
resolve(result);
})
.catch((err)=>{
console.log('err',err);
reject(err);
})
这是 avroSchema
的外观:
const avroSchema = {
"type": "record",
"name": "test",
"fields" : [
{"name": "field", "type": "long"},
]
};
执行此代码时,我得到 500-内部服务器错误
.
When I am executing this code I am getting 500 - Internal server error
.
有人可以帮助我了解我要去哪里哪里吗?
Can anyone help me to understand where I am going wrong ?
推荐答案
面向将来的用户:
这是我能够解决此问题的方法:
Here is how I was able to solve this :
const payload = {
"schema": JSON.stringify(avroSchema)
};
最后,设置有效负载后,进行如下的 POST
请求 options
:
Finally after setting the payload, make a POST
request options
as below :
const options = {
method: 'POST',
url: `${process.env.SCHEMA_REGISTRY_URL}/subjects/${topicName}-value/versions`,
headers: { 'Content-Type': 'application/vnd.schemaregistry.v1+json' },
body: payload,
json: true
}
然后提出请求:
request(options, function (error, response, body) {
if (error) {
reject(error);
}
resolve(body)
});
这篇关于使用Kafka模式注册API注册新的Avro模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文