schema-registry-serdes
Serdes for Confluent Schema Registry, compatible with Confluent Cloud.
Features
- Encode messages using avro schemas
- Decode messages with same avro schema used in the encode procedure
- Automatic pushes schema to Confluent schema registry
- Automatic fetches schema from Confluent schema registry
- Implements schema cache
- Authentication with Confluent Cloud
Installing
npm install schema-registry-serdes
Example
const SchemaRegistry = ;const encodeMessage decodeMessage = ;const schema = type: "string";const message = "testing";const encoded = await ;console; // <Buffer(13) 0 0 0 0 1 14 116 101 115 116 105 110 103>const decoded = await ;console; // testing
API Doc
This library exports a single function that receives two parameters:
- Schema registry URL
- Configuration settings
SchemaRegistry(url, config)
;
It returns an object with 4 instance methods:
- encodeMessage
- encodeById
- encodedKey
- decodeMessage
Config
The config object is used to specify additional behavior, for instance authentication and message validation before even trying to encode the message.
;
NOTE
Validating messages before encoding is an resource consuming task and is not recommended in production environments
Instance Methods
encodeMessage
Takes 4 parameters:
- topic: Topic that will be associated with the schema. Schema will have the subject
${topic}-value
- schema: is an avro schema
- message: message to be encoded
- options: parsing options used by avsc, this is an optional parameter
const encoded = await ;
encodeById
Takes 3 parameters:
- schemaId: schema id in Confluent Schema Registry
- message: message to be encoded
- options: parsing options used by avsc, this is an optional parameter
const encoded = await ;
encodeKey
Takes 4 parameters:
- topic: Topic that will be associated with the schema. Schema will have the subject
${topic}-key
- schema: is an avro schema
- message: message to be encoded
- options: parsing options used by avsc, this is an optional parameter
const encoded = await ;
decodeMessage
- message: encoded message to be decoded (
buffer
) - options: parsing options used by avsc, this is an optional parameter
const decoded = await ;