@optum/knack-sr
v1.0.0
Published
A module for interacting with the Kafka Schema Registry.
Downloads
21
Keywords
Readme
Usage
first things first...
$ npm i @optum/knack-sr
options
- domain:
[String]
(default: localhost) - schema:
[String]
(default: http) - url:
[String]
overrides all other options
Examples
const KnackSr = require('@optum/knack-sr');
const options = {
url: 'http://localhost:8081'
};
const schemaId = 123;
const sr = new KnackSr(options);
const schemaResponse = await sr.getSchemaById(schemaId);
console.log(schemaResponse);
const KnackSr = require('@optum/knack-sr');
const options = {
url: 'http://localhost:8081'
};
const topic = 'knack-test-topic-v1';
const sr = new KnackSr(options);
const keySubject = `${topic}-${key}`;
const keySchemaResponse = await sr.getSchemaBySubject(keySubject);
const valueSubject = `${topic}-${value}`;
const valueSchemaResponse = await sr.getSchemaBySubject(valueSubject);
console.log(keySchemaResponse);
console.log(valueSchemaResponse);
const KnackSr = require('@optum/knack-sr');
const topic = 'knack-test-topic-v1';
// can be string or json
const avroSchema = {
"type": "record",
"name": "messageInfo",
"namespace": "io.knack.schemas.avro",
"fields": [
{
"name": "content",
"type": "string"
},
{
"name": "channel",
"type": ["null", "string"],
"default": null
}
]
};
// example of using default options
const sr = new KnackSr();
const valueSubject = `${topic}-${value}`;
const registration = await sr.registerSchema({
schema: avroSchema,
subject: valueSubject
});