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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@namaste/kafka-schema-registry-client

v0.3.0

Published

Kafka Schema Registy client.

Readme

@namaste/kafka-schema-registry-client

Kafka Avro schema registry client that supports:

  • Serializing messages
  • Publishing locally defined schemas to registry
  • Selecting schema versions to use for serializing messages
  • Deserializing messages
  • Pre-fetching latest schemas for topics from registry

Installation

npm i --save @namaste/kafka-schema-registry-client

or

yarn add @namaste/kafka-schema-registry-client

Usage

Create registry client

const { SchemaRegistry } = require('@namaste/kafka-schema-registry-client');

const connectionConfig = {
  url: 'https://my.fake.schema.registry.url:3030',
  auth: {
    username: 'fakeusername',
    password: 'fakepassword',
  },
};

const schemaRegistry = new SchemaRegistry(connectionConfig);

Publish locally defined avro schemas

Note: Schemas are only published if changed. If schema version has already been published, it is skipped. Note: Published schemas are also cached and set to be used for serialization.

const topicSchemaDefinitions = {
  'topic': {
    key: {
      name: 'testKey',
      type: 'string',
      namespace: 'registry.test',
    },
    value: {
      name: 'testValue',
      type: 'record',
      namespace: 'registry.test',
      fields: [
        {
          name: 'text',
          type: 'string',
        },
        {
          name: 'newField',
          type: ['null', 'string'],
          default: null,
        },
      ],
    },
  }
};
await schemaRegistry.publishSchemas(topicSchemaDefinitions);

Caching schemas from registry and setting them to be used for serialization

Note: Usefull for producers when schemas are not defined locally or should not be automatically published by producer.

Specifying versions for topics

Specific schema versions will be fetched and set active.

await schemaRegistry.useSchemas({
  'topic_name': {
    key: 'latest',
    value: '2',
  }
});

Fetch and set active latest versions of all registered topics

await schemaRegistry.useSchemas();

Fetch and set active latest versions for specific topics

await schemaRegistry.useSchemas(['topic_name_1', 'topic_name_2']);

Serializing message

Note: Schemas should be set to be used for serialization by either of two methods described above prior to serialization. Note: Schema version used for serialization is recorded in message headers.

const message = {
  key: 'key text',
  value: {
    text: 'some text',
    number: 4,
    array: ['test1', 'test2'],
    newField: 'more text',
  },
  partition: 2,
  headers: {},
  timestamp: '2019-01-01T22:22:22.000Z',
};
const serializedMessage = schemaRegistry.serializeMessage(message, 'topic');

Pre-fetching schemas for deserialization

Note: This is optional as schemas that has not been fetched yet are fetched on deserialization attempt.

const topicsToPrefetchSchemasFor = ['topicname'];
await schemaRegistry.fetchLatestSchemas(topicsToPrefetchSchemasFor);

Deserializing messsage

Note: Schema version used for deserialization is defined in message headers.

 const deserializedMessage = await schemaRegistry.deserializeMessage(serializedMessage, 'topic');

API

constructor

Creates new instance of schema registry.

Parameters

  1. connectionConfig - object that has following shape:
  • url - schema registry URL
  • auth - basic auth config, must have:
  • auth.username
  • auth.password

publishSchemas(topicSchemaDefinitions): Promise<void>

Publishes local shemas to registry and sets them to be used for messages serialization.

Paramerters

  1. topicSchemaDefinitions - object that has following shape:
  • [topic_name]:
  • [topic_name].key - optional. Avro schema definition for message key.
  • [topic_name].value - optional. Avro schema definition for message value.

serializeMessage(message, 'topic'): serializedMessage

Serializes message using key and value schemas for the topic. Schema versions to be used are defined with either publishSchemas or useSchemas methods.

Parameters

  1. message - message to be serialized
  2. topic - topic the message is going to be published to

async useSchemas([topicVersionDefinitions]): Promise<void>

Fetches schema versions for specified topics from registry and sets them to be used for messages serialization.

Paramerters

  1. topicVersionDefinitions - Optional. Either a string array of topic names or an object that specifies key and value versions:

When object, must have following shape:

  • [topic_name]:
  • [topic_name].key - optional. Schema version string. Can be version number or string latest.
  • [topic_name].value - optional. Schema version string. Can be version number or string latest.

When array, must list topic names.

Note: If no topicVersionDefinitions are passed to useSchemas, schema registry will fetch and set as active latest verions for all subjects (keys and values for all topics).

async fetchLatestSchemas(topicsToPrefetchSchemasFor): Promise<void>

Fetches latest schemas for specified topics from registry.

Paramerters

  1. topicsToPrefetchSchemasFor - array of topic name strings

async deserializeMessage(serializedMessage, 'topic'): Promise<deserializedMessage>

Deserializes message using key and value schemas for the topic. Schema versions to be used are retreived from message headers.

Parameters

  1. serializedMessage - message to be deserialized
  2. topic - topic the message was published to