Registry / messaging / avro-schema-registry

avro-schema-registry

JSON →
library2.1.5jsnpmunverified

A JavaScript library (v2.1.5) for Confluent Schema Registry integration, enabling Avro serialization and deserialization of Kafka messages. Requires only avsc as a peer dependency. Caches schemas to reduce network calls. Supports encoding/decoding by schema, ID, or topic. Provides authentication via URL or options object. Updated irregularly; last release in 2023.

npm install avro-schema-registry
INSTALL
IMPORT
SIG · AVRO-SCHEMA-REGIST
A
avro-schema-registry
messagingjavascriptv2.1.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import registry from 'avro-schema-registry'
const { registry } = require('avro-schema-registry')
The module exports a single function that returns a registry object. Use default import or require().
Registry
type Registry = ReturnType<typeof import('avro-schema-registry')>
import { Registry } from 'avro-schema-registry'
TypeScript users can infer type via ReturnType; there is no explicit named export for the registry type.
require()
const registry = require('avro-schema-registry')('https://host:8081')
const registry = require('avro-schema-registry').default('https://host:8081')
CommonJS require returns the function directly; no .default needed.

Shows how to create a registry client, encode an Avro message by topic and schema, then decode it using async/await.

import registry from 'avro-schema-registry'; import avsc from 'avsc'; const reg = registry('https://localhost:8081', { username: 'user', password: 'pass' }); const schema = { type: 'record', name: 'Test', fields: [{ name: 'field1', type: 'string' }] }; const message = { field1: 'hello' }; async function example() { const encoded = await reg.encodeMessage('test-topic', schema, message); console.log('Encoded:', encoded); const decoded = await reg.decode(encoded); console.log('Decoded:', decoded); } example().catch(console.error);
Debug
Known issues
gotcharequire() returns a factory function, not an object with methods. Must call it with URL immediately.
fix
Use const registry = require('avro-schema-registry')('https://url') instead of const registry = require('avro-schema-registry')
affects: >=2.0.0
deprecateddecodeMessage method exists only for backward compatibility; use decode instead.
fix
Replace registry.decodeMessage(msg) with registry.decode(msg)
affects: >=2.0.0
gotchaencodeMessage registers the schema under subject `${topic}-value`. For keys, use encodeKey with subject `${topic}-key`. Confusingly, encodeMessage does not handle keys.
fix
Use encodeKey(topic, schema, message) for key schemas and encodeMessage(topic, schema, message) for value schemas.
affects: >=2.0.0
breakingFrom v2.0.0, the package is ESM-only but README shows require(). If using native ESM, require() fails.
fix
Use ES import syntax in ESM context, or use dynamic import() in Node environments that support it. For CommonJS, keep using require() as shown.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: registry.decode is not a function
Calling require('avro-schema-registry') without invoking the factory function, so you get the function itself instead of the registry object.
fix
const registry = require('avro-schema-registry')('https://your-registry:8081');
Error: Cannot find module 'avsc'
avsc is a peer dependency and must be installed separately.
fix
npm install avsc
Error: connect ECONNREFUSED <host>:8081
Schema Registry URL is incorrect or not reachable.
fix
Verify the URL and ensure Schema Registry is running. If using authentication, check credentials.
Error: Schema not found for id X
The schema ID does not exist in the registry, or the schema was deleted.
fix
Register the schema first using encodeMessage/encodeKey, or provide a valid schema ID.
Upgrade
Version history
2.1.5latest on npm
Audit
Dependencies
avscrequiredpeer dependency for Avro schema parsing and serialization
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources