Closed paulcull closed 4 years ago
Hey Paul, thanks for using kafka-node-avro, this package is using fromBuffer
mechanism from avsc on the decode
I made some research but had no luck on why avsc is not processing this field, you can overwrite the default encoder by
const KafkaAvro = require('kafka-node-avro');
const Settings = {
"kafka": {
"kafkaHost": "127.0.0.1:9092"
},
"schema": {
"registry": "http://127.0.0.1:8081"
"topics" : [{ "name" : "cc_payments" }]
}
};
KafkaAvro.init(Settings).then( kafka => {
kafka.schemas.getByName('cc_payments').then( schema => {
schema.decode = function(message){
return schema.parser.fromBuffer(message.slice(5)); // Default <-- Overwrite
};
let consumer = kafka.addConsumer('cc_payments', { kafkaHost: "127.0.0.1:9092", groupId: "TestGroupOne", fromOffset: "latest" });
consumer.on('message', message => {
console.log(message);
});
consumer.on('error', error => {
console.log(error);
});
}, error => {
console.log(error);
});
}, error => {
console.log(error);
});
on the
schema.decode = function(message){
return schema.parser.fromBuffer(message.slice(5)); // Default <-- Overwrite
};
message : Raw AVRO encoded event
schema : { id : Number, name : String, version : Number, key_fields : Arrary, definition : String, // raw responmse from the schema registry. parser : avro.Type.forSchema }
NOTE: Just make sure to return the value.
Example :
schema.decode = function(message){
const decoded = schema.parser.fromBuffer(message.slice(5));
decoded.amount = parseInt(decoded.amount);
return decoded
};
Hi,
I've got a schema that has a bytes type (logicalType: Decimal) in the schema, but when I'm reading the message its not decoding that buffer. I can't seem to find anything in the docs.
Is there a way to apply the schema to the message including these types ?
Schema `
`
Response `
`
Code `
`