open-index/open-npm huggingface dataset:
npm package: @optum/knack-cli
Description: A cli for working with Apache Kafka development.
Author: lxghtless
Latest version: 1.4.1

<h2 align="center">
  knack-cli
</h2>

<p align="center">
  A cli for working with Apache Kafka development.
</p>

<p align="center">
  <a href="https://www.npmjs.com/package/@optum/knack-cli"><img src="https://img.shields.io/npm/v/@optum/knack-cli?color=blue"></a>
  <a href="https://github.com/xojs/xo"><img src="https://img.shields.io/badge/code_style-XO-5ed9c7.svg"></a>
</p>

## Usage

<b>first things first...</b>

```shell
$ npm i -g @optum/knack-cli
```

### Help Menu

```shell
$ knack --help

  A cli for working with Apache Kafka development.

   _   __ _   _   ___   _____  _   __
  | | / /| \ | | / _ \ /  __ \| | / /
  | |/ / |  \| |/ /_\ \| /  \/| |/ / 
  |    \ | . ` ||  _  || |    |    \ 
  | |\  \| |\  || | | || \__/\| |\  \ 
  \_| \_/\_| \_/\_| |_/ \____/\_| \_/


  command register-avro-schema
      options
      --avsc alias --a string avro schema input
      --topic alias --t [string] 
      --type alias --ty string subject type (i.e. key or value)
  
  command verify-avro-schema
      options
      --avsc alias --a string avro schema input
      --data alias --d string path to json file containing data
      --show alias --s [string] show data after encode -> decode
  
  command convert-avsc
  convert an avsc to other formats
      options
      --avsc alias --a string avro schema input
      --format alias --f string target format: es (elastic mapping), json (json schema)
      --output alias --o string file output path
  
  command convert-json
  convert a json schema to avro
      options
      --json alias --j string json schema input
      --output alias --o string file output path
  
  command consume
      options
      --consumerConfig alias --cc [string] path to json file containing librd consumer settings
      --topicConfig alias --tc [string] path to json file containing librd topic settings
  
  command produce
      options
      --producerConfig alias --pc [string] path to json file containing librd producer settings
      --topic alias --t [string] 
      --key alias --k [string] path to json file containing key data
      --value alias --v string path to json file containing value data
      --count alias --c [string] number of times to run the action
  
  command check-kafka
      options
      --brokers alias --b [string] comma separated list of brokers
```
npm package: @optum/knack-consumer
Description: A module for consuming messages from Apache Kafka.
Author: lxghtless
Latest version: 1.0.0

<h2 align="center">
  knack-consumer
</h2>

<p align="center">
  A module for consuming messages from Apache Kafka.
</p>

<p align="center">
    <a href="https://www.npmjs.com/package/@optum/knack-consumer"><img src="https://img.shields.io/npm/v/@optum/knack-consumer?color=blue"></a>
  <a href="https://github.com/xojs/xo"><img src="https://img.shields.io/badge/code_style-XO-5ed9c7.svg"></a>
</p>

## Usage

<b>first things first...</b>

```shell
$ npm i @optum/knack-consumer node-rdkafka@2.7
```

<b>options</b>

- topics: `[Array]` array of topics to subscribe
- consumerConfig: `[Object]` librd consumer config
- topicConfig: `[Object]` librd topic config
- flowMode: `[Boolean]` run flow mode or control message intake cadence
- logger: `[Object]` logger object with trace, debug, info, error methods
- onData: `Function` handler for each record consumed

## Examples

```js
const knackConsumer = require("@optum/knack-consumer");

const consumerConfig = {
	"client.id": "my-kafka-client-v1",
	"group.id": "my-kafka-group-v1",
	"metadata.broker.list": "localhost:9092",
	"socket.keepalive.enable": true,
	"enable.auto.commit": true
};

const topicConfig = {
	"auto.offset.reset": "earliest",
	// eslint-disable-next-line camelcase
	event_cb: () => {}
};

const topic = "knack-test-topic-v1";

const handler = ({ key, value, topic, timestamp }) => {
	// do stuff with record
};

// connect consumer with options
const testConsumer = await knackConsumer.connect({
	topics: [topic],
	consumerConfig,
	topicConfig,
	onData: handler
});

process.on("SIGINT", async () => {
	await knackConsumer.disconnect();
});
```
npm package: @optum/knack-consumer-client
Description: A module for consuming records with Apache Kafka.
Author: lxghtless
Latest version: 1.4.1

<h2 align="center">
  knack-consumer-client
</h2>

<p align="center">
  A module for consuming records from Apache Kafka with integrated avro support.
</p>

<p align="center">
    <a href="https://www.npmjs.com/package/@optum/knack-consumer-client"><img src="https://img.shields.io/npm/v/@optum/knack-consumer-client?color=blue"></a>
  <a href="https://github.com/xojs/xo"><img src="https://img.shields.io/badge/code_style-XO-5ed9c7.svg"></a>
</p>

## Usage

<b>first things first...</b>

```shell
$ npm i @optum/knack-consumer-client
```

<b>options</b>

- subscriptions: `Array` array of subscription objects
    + subscription: `[Object]` consumer subscription info
        * topic: `[String]` name of topic
        * handler: `[Function]` handler for each record consumed
- consumerConfig: `[Object]` librd consumer config
- topicConfig: `[Object]` librd topic config
- flowMode: `[Boolean]`  run flow mode or control message intake cadence
- logger: `[Object]`  logger object with trace, debug, info, error methods
- srOptions: `[Object]`: options to pass to knack-sr

## Examples

```js
const knackConsumerClient = require('@optum/knack-consumer-client');

const consumerConfig = {
    'client.id': 'my-kafka-client-v1',
    'group.id': 'my-kafka-group-v1',
    'metadata.broker.list': 'localhost:9092',
    'socket.keepalive.enable': true,
    'enable.auto.commit': true
};

const topicConfig = {
    'auto.offset.reset': 'earliest',
    // eslint-disable-next-line camelcase
    event_cb: () => {}
};

const topic = 'knack-test-topic-v1';

const handler = ({key, value, topic, timestamp}) => {
    // do stuff with record
};

// connect consumer with options
const testConsumer = await knackConsumerClient.connect({
    subscriptions: [{
        topic,
        handler
    }],
    consumerConfig,
    topicConfig,
    srOptions: {
        url: 'http://localhost:8081'
    }
});

process.on('SIGINT', async () => {
    await knackConsumerClient.disconnect();
});
```
npm package: @optum/knack-producer
Description: A module for publishing to Apache Kafka.
Author: lxghtless
Latest version: 1.0.0

<h2 align="center">
  knack-producer
</h2>

<p align="center">
  A module for publishing to Apache Kafka.
</p>

<p align="center">
     <a href="https://www.npmjs.com/package/@optum/knack-producer"><img src="https://img.shields.io/npm/v/@optum/knack-producer?color=blue"></a>
  <a href="https://github.com/xojs/xo"><img src="https://img.shields.io/badge/code_style-XO-5ed9c7.svg"></a>
</p>

## Usage

<b>first things first...</b>

```shell
$ npm i @optum/knack-producer node-rdkafka@2.7
```

`node-rdkafka` is now a peer dependency to give flexibility in versions

<b>options</b>

- producerConfig: `[Object]` librd producer config

## Examples

```js
const {
	KnackProducer,
	KnackHighLevelProducer
} = require("@optum/knack-producer");

const options = {
	producerConfig: {
		"metadata.broker.list": ["localhost:9092"]
	}
};

// example data
const topic = "knack-test-topic-v1";
const key = Buffer.from("key-001");
const value = Buffer.from("hello from knack producer");

// use standard producer
const knackProducer = new KnackProducer(options);
await knackProducer.connect();

knackProducer.produce(topic, null, value, key, Date.now());

// use high level producer
const knackHighLevelProducer = new KnackHighLevelProducer(options);
await knackHighLevelProducer.connect();

producer.produceAsync(topic, null, value, key);

knackHighLevelProducer.produce(
	topic,
	null,
	value,
	key,
	Date.now(),
	(err, offset) => {
		// The offset if our acknowledgement level allows us to receive delivery offsets
		console.log(offset);
	}
);
```
npm package: @optum/knack-producer-client
Description: A module for producing records with Apache Kafka.
Author: lxghtless
Latest version: 1.4.1

<h2 align="center">
  knack-producer-client
</h2>

<p align="center">
  A module for publishing records to Apache Kafka with integrated avro support.
</p>

<p align="center">
 <a href="https://www.npmjs.com/package/@optum/knack-producer-client"><img src="https://img.shields.io/npm/v/@optum/knack-producer-client?color=blue"></a>
  <a href="https://github.com/xojs/xo"><img src="https://img.shields.io/badge/code_style-XO-5ed9c7.svg"></a>
</p>

## Usage

<b>first things first...</b>

```shell
$ npm i @optum/knack-producer-client node-rdkafka@2.7
```

<b>options</b>

- useHighLevelProducer: `[Boolean]` flag indicating to use the highlevel producer over the standard one
- producerConfig: `[Object]` librd producer config
- srOptions: `[Object]`: options to pass to knack-sr

## Examples

<b>simple</b>

```js
const KnackProducerClient = require("@optum/knack-producer-client");

const options = {
	producerConfig: {
		"metadata.broker.list": ["localhost:9092"]
	},
	srOptions: {
		url: "http://localhost:8081"
	}
};

const topic = "knack-test-topic-v1";
const key = { id: "1234" };
const value = { content: "from knack producer client" };

// await getting the producer so it lazy loads a connection the first time a message goes through
const producer = await KnackProducerClient.resolveInstance(options);

producer.publish({
	topic,
	key,
	value
});

// calling for an instance with the same options with give back the same producer, so it will manage different connections for you
const queued = KnackProducerClient.resolveInstance(options).publish({
	topic,
	key,
	value
});
```

<b>also simple, but one more step</b>

```js
const KnackProducerClient = require("@optum/knack-producer-client");

const options = {
	producerConfig: {
		"metadata.broker.list": ["localhost:9092"]
	},
	srOptions: {
		url: "http://localhost:8081"
	}
};

const topic = "knack-test-topic-v1";
const key = { id: "1234" };
const value = { content: "from knack producer client" };

// connect at app start up or whenever
await KnackProducerClient.connectInstance(options);

// grab the producer through the instance method without needing to await it
const producer = KnackProducerClient.instance(options);

producer.publish({
	topic,
	key,
	value
});
```
npm package: @optum/knack-sr
Description: A module for interacting with the Kafka Schema Registry.
Author: lxghtless
Latest version: 1.0.0

<h2 align="center">
  knack-sr
</h2>

<p align="center">
  A module for interacting with the Kafka Schema Registry.
</p>

<p align="center">
 <a href="https://www.npmjs.com/package/@optum/knack-sr"><img src="https://img.shields.io/npm/v/@optum/knack-sr?color=blue"></a>
  <a href="https://github.com/xojs/xo"><img src="https://img.shields.io/badge/code_style-XO-5ed9c7.svg"></a>
</p>

## Usage

<b>first things first...</b>

```shell
$ npm i @optum/knack-sr
```

<b>options</b>

- domain: `[String]` (default: localhost)
- schema: `[String]` (default: http)
- url: `[String]`  overrides all other options

## Examples

<p>
    read schema by id
</p>

```js
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);
```

<p>
    read schema by subject
</p>

```js
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);
```

<p>
    register schema
</p>

```js
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
});
```