avro-cado: Encode and Decode using a schema-registry
- Simple package that implements Avro encoding and decoding
- Written in Typescript
- Follows the Avro serialization conventions of Confluent's Schema Registry. During deserialization, schemas are obtained from the registry using their 4-byte id prefix. When serializing data, schemas are registered to the registry and obtain the corresponding 4-byte id prefix.
- Easy to use interface. All of Confluent's Schema Registry flows are implemented in the package
- Supports evolution. Converts Avro-encoded payloads into a format specified by the application's Avro schema.
Sample use case
- We use this to encode and decode messages when consuming and producing to Kakfa
npm install avro-cado
// Avro schemaconst avroSchema =type: "record"name: "TestMessage"namespace: "com.flipp.node.kafka.TestMessage"doc: "Properties related to a TestMessage."fields:name: "key"type: "string"doc: "The the key for the message"name: "text"type: "string"doc: "The text for the message";
// package optionsconst opts: Options =schemaRegistry: ""numRetries: 10 // number of attempts to call schemaRegistrywrapUnions: "auto" // avsc optionsubject: "test-value" // subject for schema registrationschema: avroSchema // schema object as needed for avsc;
Create Encoder and use it
const encodeFunc = await ;// encode a messageconst encoded: Buffer = ;
Create Decoder and use it
const decodeFunc = ;// decode a messageconst decoded = await ;
- Ensure typescript is installed:
npm install -g typescript
- Install all dependencies:
- Make changes
npm run package. This will remove the
tscand add the release directory back to git. The release directory needs to be updated every commit to include changes in the library.
- Update the
- Add your changes to git, and commit.
Support / Contributing
Before opening an issue or pull request, please read the Contributing guide.