1.0.0 • Published 2 years ago

wisrtoni40-confluent-schema v1.0.0

Weekly downloads
6
License
ISC
Repository
github
Last release
2 years ago

wisrtoni40-confluent-schema

Install

npm i wisrtoni40-confluent-schema --save

Table of Contents

Quickstart

Consumer

Full Example

import {
  ConfluentAvroStrategy,
  ConfluentMultiRegistry,
  ConfluentSubResolveStrategy,
} from 'wisrtoni40-confluent-schema';

const registryHost = 'http://localhost:8585,http://localhost:8585,http://localhost:8585';

const schemaRegistry = new ConfluentMultiRegistry(registryHost);
const avro = new ConfluentAvroStrategy();
const resolver = new ConfluentSubResolveStrategy(schemaRegistry, avro);

const data = new Buffer();
resolver.resolve(data).then(val => console.log(val));

Producer

Full Example

import {
  ConfluentAvroStrategy,
  ConfluentMultiRegistry,
  ConfluentPubResolveStrategy,
} from 'wisrtoni40-confluent-schema';

const registryHost = 'http://localhost:8585,http://localhost:8585,http://localhost:8585';
const topic = 'testing.topic'

const schemaRegistry = new ConfluentMultiRegistry(registryHost);
const avro = new ConfluentAvroStrategy();
const resolver = new ConfluentPubResolveStrategy(schemaRegistry, avro, topic);

const data = { name: 'name', age: 18 };
resolver.resolve(data).then(buf => console.log(buf));

Feature

  • 提供多個Brokers的Confluent Avro Schema解析API

API

ConfluentMultiRegistry

Class implements SchemaRegistry,多個Brokers的Confluent Schema Registry

constructor

ConfluentMultiRegistry的建構值

ParameterTypeRequiredDefaultDescription
hoststringRequiredundefinedBrokers Host 多筆可用,隔開,如: 'http://localhost:8585,http://localhost:8585,http://localhost:8585'

ConfluentAvroStrategy

Class implements AvroResolveStrategy,Confluent Avro Schema的解析策略

ConfluentSubResolveStrategy

Class implements ConsumerResolveStrategy,Confluent Schema Consumer的解析器

constructor

ConfluentSubResolveStrategy的建構值

ParameterTypeRequiredDefaultDescription
schemaRegistrySchemaRegistryRequiredundefinedSchema Registry
avroResolverAvroResolveStrategyRequiredundefinedAvro解析策略

Methods

resolve

將Avro資料解析成特定JSON格式

ParameterTypeRequiredDefaultDescription
inputstring | BufferRequiredundefined要解析的資料
returnsPromise<T>Requiredundefined回傳解析後的資料

ConfluentPubResolveStrategy

Class implements ProducerResolveStrategy,Confluent Schema Producer的解析器

constructor

ConfluentPubResolveStrategy的建構值

ParameterTypeRequiredDefaultDescription
schemaRegistrySchemaRegistryRequiredundefinedSchema Registry
avroResolverAvroResolveStrategyRequiredundefinedAvro解析策略
destinationstringRequiredundefined發送資料的目的地

resolve

將特定JSON資料解析成Avro

ParameterTypeRequiredDefaultDescription
inputany | any[]Requiredundefined要解析的資料
returnsPromise<Buffer | Buffer[]>Requiredundefined回傳解析後的Avro