npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

schema-registry-serdes

v1.1.1

Published

Confluent Schema Registry serdes that use avro schemas.

Downloads

122

Readme

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 = require("schema-registry-serdes");
const { encodeMessage, decodeMessage } = SchemaRegistry("https://localhost.com:8081");
const schema = {type: "string"};
const message = "testing";
const encoded = await encodeMessage("topic", schema, message);
console.log(encoded);   // <Buffer(13) 0 0 0 0 1 14 116 101 115 116 105 110 103>
const decoded = await decodeMessage(encoded);
console.log(decoded);   // testing

API Doc

This library exports a single function that receives two parameters:

  • Schema registry URL
  • Configuration settings
SchemaRegistry(url, config)
SchemaRegistry(
  "https://www.host.com", 
  { 
    key: "provided key", 
    secret: "provided secret", 
    validateMessages: false
  }
);

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.

SchemaRegistry(
  "https://www.host.com", 
  { 
    key: "provided key",        // key or username
    secret: "provided secret",  // secret or password  
    validateMessages: true      // Flag for validation before encoding
  }
);
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 encodeMessage("topic", schema, message);
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 encodeById(1, message);
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 encodeKey("topic", schema, message);
decodeMessage
  • message: encoded message to be decoded (buffer)
  • options: parsing options used by avsc, this is an optional parameter
const decoded = await decodeMessage(encodedMessage);