schema-registry-client
TypeScript icon, indicating that this package has built-in type declarations

1.5.2 • Public • Published

schema-registry-client

Schema registry client for Confluent's Avro Schema Registry.

Build Status codecov

Usage

npm install --save schema-registry-client

Create Schema

import { SchemaRegistryClient } from './SchemaRegistryClient';
 
const schemaRegistry = SchemaRegistryClient.create('http://localhost:8081');
 
interface IData {
  first: string;
  last: string;
  age: number;
}
 
const schema = {
  "name": "SerializationTest",
  "namespace": "com.example",
  "type": "record",
  "fields": [
    { "name": "first", "type": ["null", "string"] },
    { "name": "last", "type": "string" },
    { "name": "age", "type": ["null", "int"] },
  ]
};
 
schemaRegistry
  .createSchema('subjectName', schema)
  .then((schemaInfo)=> { console.log(`Created schema: ${schemaInfo.subject} with id: ${schemaInfo.id}`) })

Serialize JSON

import { SchemaRegistryClient } from './SchemaRegistryClient';
 
const schemaRegistry = SchemaRegistryClient.create('http://localhost:8081');
 
interface IData {
  first: string;
  last: string;
  age: number;
}
 
const data: IData = {
  'age': 60,
  'first': 'firstName',
  'last': 'lastName',
}
 
schemaRegistry
  .encodeBySubject(data, 'subjectName')
  .then(schemaRegistryAvroBuffer => console.log(schemaRegistryAvroBuffer))

Deserialize JSON

import { SchemaRegistryClient } from './SchemaRegistryClient';
 
const schemaRegistry = SchemaRegistryClient.create('http://localhost:8081');
 
interface IData {
  first: string;
  last: string;
  age: number;
}
 
const buffer = /* consume message buffer from kafka */
 
schemaRegistry
  .decode<IData>(buffer)
  .then(data => {
    console.log(`First Name: ${data.first}
    Last Name: ${data.last}
    Age: ${data.age}`)
  })

Future Development

  • Support schema registry multiserver configuration

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.5.2
    2
    • latest

Version History

Package Sidebar

Install

npm i schema-registry-client

Weekly Downloads

2

Version

1.5.2

License

MIT

Unpacked Size

40.2 kB

Total Files

61

Last publish

Collaborators

  • nomnomnpm