我正在尝试使用kafka-node-avro
库将数据推送到现有主题。我已经使用 curl 和主题将模式添加到 SchemaRegistry 中。我收到以下错误:
Error: Topic name or id is needed to build Schema
at new Shema (/work/node_modules/kafka-node-avro/lib/schema.js:7:41)
at Object.Pool.getByName (/work/node_modules/kafka-node-avro/lib/schemaPool.js:70:10)
at new Promise (<anonymous>)
我的代码片段如下:
const Settings = {
"kafka" : {
"kafkaHost" : config.KafkaHost
},
"schema": {
"registry" : config.KafkaRegistry
}
};
console.log("settings registry: ", config.KafkaRegistry);
console.log("settings kafkaHost: ", config.KafkaHost)
KafkaAvro.init(Settings).then( kafka => {
const producer = kafka.addProducer();
let payloads = [
{
topic: 'classifier-response-test',
messages: JSON.stringify(kafkaData)
}
];
producer.send(payloads).then( success => {
// Message was sent encoded with Avro Schema
console.log("message sent ! Awesome ! :) ")
}, error => {
// Something wrong happen
console.log("There seems that there is a mistake ! try Again ;) ")
console.log(error)
});
} , error => {
// something wrong happen
console.log("There seems that there is a global mistake ! try Again ;) ")
console.log(error)
});