Code Monkey home page Code Monkey logo

avro-schema-registry's Introduction

avro-schema-registry

Confluent Schema Registry implementation to easily serialize and deserialize kafka messages with only one peer depencency.

Quickstart

const registry = require('avro-schema-registry')('https://host.com:8081');

const schema = {type: 'string'};
const message = 'test message';

registry.encodeMessage('topic', schema, message)
  .then((msg) => {
    console.log(msg);   // <Buffer 00 00 00 00 01 18 74 65 73 74 20 6d 65 73 73 61 67 65>

    return registry.decode(msg);
  })
  .then((msg) => {
    console.log(msg);  // test message
  });

registry.encodeById(1, message)
  .then((msg) => {
    console.log(msg);   // <Buffer 00 00 00 00 01 18 74 65 73 74 20 6d 65 73 73 61 67 65>

    return registry.decode(msg);
  })

Install

npm install avsc // if not already installed
npm install avro-schema-registry

Doc

The module exports one function only, which expects a url parameter, which is a Confluent Schema Registry endpoint. The function returns an object with two methods.

Every method returns a Promise.

Every method uses an internal cache to store already retrieved schemas and if the same id or schema is used again it won't perform another network call. Schemas are cached with their parsing options.

decode

Parameters:

  • msg: object to decode
  • parseOptions: parsiong options to pass to avsc.parse, default: null

Decodes an avro encoded buffer into a javascript object.

decodeMessage

Same as decode, only exists for backward compatibility reason.

encodeKey

Parameters:

  • topic: the topic to register the schema, if it doesn't exist already in the registry. The schema will be put under the subject ${topic}-key
  • schema: object representing an avro schema
  • msg: message object to be encoded
  • parseOptions: parsiong options to pass to avsc.parse, default: null

Encodes an object into an avro encoded buffer.

encodeMessage

Parameters:

  • topic: the topic to register the schema, if it doesn't exist already in the registry. The schema will be put under the subject ${topic}-value
  • schema: object representing an avro schema
  • msg: message object to be encoded
  • parseOptions: parsiong options to pass to avsc.parse, default: null

Encodes a message object into an avro encoded buffer.

encodeById

Parameters:

  • id: schema id in the registry
  • msg: message object to be encoded
  • parseOptions: parsiong options to pass to avsc.parse, default: null

Encodes a message object into an avro encoded buffer by fetching the schema from the registry.

Peer dependency

The module has no dependency, only one peer dependency: avsc

avro-schema-registry's People

Contributors

bencebalogh avatar katsanva avatar terlar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.