Reputation: 804
I'm using kafka to receive data from the source, I'm working on the consumer app which is written in Node.js
and using kafka-node
to connect to kafka server. On other hand the producer is written in Java
and they are using some kafka streaming library to produce the avro messages with schema.
I'm able to receive the messages but they are avro serialized, below is the serialized message format which I'm receiving -
value: '\u0000\u0000\u0001�H\u0002\u00142020-10-01\u0002\u000e1000001\u0002\u000e2668422\u000202021-06-21T09:34:19.003Z\u0000\u0002\u000e3010985\u0002T83dc24eb6aac\u0002.2021-06-21T09:34:20.453'
I'm trying to deserialize it but unable to do with avsc
npm module because avsc only accepts buffer data format. I'm not sure about the type of the avro message data format.
We also have schema registery for these messages. So I just need help to deserialize the messages in node.js I know there is npm module avsc
which helps to encode decode the avro messages but it works only with buffer.
Please help me to understand how can I deserialize the avro messages in Nodejs.
Thanks!!!
Upvotes: 0
Views: 1506
Reputation: 34
const v8 = require("v8");
const str =
"<'\u0000\u0000\u0001�H\u0002\u00142020-10-01\u0002\u000e1000001\u0002\u000e2668422\u000202021-06-21T09:34:19.003Z\u0000\u0002\u000e3010985\u0002T83dc24eb6aac\u0002.2021-06-21T09:34:20.453'>";
console.log(v8.deserialize(v8.serialize(str)));
console.log(`${Buffer.from(str, "utf8")}`);
Upvotes: 0