# @hoangthequyen/rd-kafka-node

> A node-rdkafka wrapper with extended features

Latest version **1.0.2** (published 2021-02-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install @hoangthequyen/rd-kafka-node
pnpm add @hoangthequyen/rd-kafka-node
yarn add @hoangthequyen/rd-kafka-node
bun add @hoangthequyen/rd-kafka-node
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-02-28 |
| First published | 2021-02-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 28.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | hoangthequyen01@gmail.com |
| Maintainers | hoangthequyen |
| Keywords | kafka, node-rdkafka, rd-kafka, kafka-client |

## Links

- npm: https://www.npmjs.com/package/@hoangthequyen/rd-kafka-node
- Repository: https://github.com/HoangTheQuyen96/rd-kafka-node
- Homepage: https://github.com/HoangTheQuyen96/rd-kafka-node#readme
- Issues: https://github.com/HoangTheQuyen96/rd-kafka-node/issues
- npm.io page: https://npm.io/package/@hoangthequyen/rd-kafka-node

## Dependencies (1)

- [node-rdkafka](https://npm.io/package/node-rdkafka.md) ^2.10.1

## Recent versions

- 1.0.2 (latest) — 2021-02-28
- 1.0.1 — 2021-02-28
- 1.0.0 — 2021-02-28

## README

# node-kafka-client

A wrapper library of [node-rdkafka](https://github.com/Blizzard/node-rdkafka) with extended features

## Install

> Important: We are using `node-rdkafka 2.10.1`

`npm install @kafka/node-kafka-client`

## Usage

### Consumer

```js
const { Consumer } = require("@kafka/node-kafka-client");

const consumer = new Consumer({
  // Required options
  name: "test-consumer-name",
  groupId: "test-group-id",
  host: "localhost:9092",
  topic: "test-topic",

  // Optional options
  connectTimeout: 5000,
  mode: "non-flowing",
  intervalFetchMessage: 10, // Only affect for non-flowing mode
  numMsgFetchPerTime: 1, // Only affect for non-flowing mode
  logger: null,
});

consumer.listen(async (data) => {
  console.log("Listen data:", data);
});
```

The consumer inherit all `node-rdkafka` configuration options for you to set or override. Using snippet config below and reference original [node-rdkafka](https://github.com/Blizzard/node-rdkafka) lib for more detail of configuration.

```js
{
  ...
  rdKafkaConfig: {
    debug: "all",
  },
  rdKafkaTopicConfig: {
    "auto.offset.reset": "latest",
  },
}
```

```js
consumer.on("event.log", console.log);
```

### Flowing mode:

- Pros
  - Concurrent handler processing message.
- Cons
  - Might cause OOM (out-of-memory) when start the consumer with the lag offset too much
  - Need to handler duplicated messages.
  - Each consumer will block a thread of libuv.
- Suitable for:
  - Small processing time handler.
  - The result of processing messages is independent.

### Non-flowing:

- Pros:
  - Handle one-by-one messages. The next message just consumed after the previous committed
  - It's not block the thread of libuv.
  - Fully control the interval and number of message to fetch
- Cons:
  - Non-concurrency consume messages, higher latency compare to flowing mode.
- Suitable for:
  - High demand of consistency handling messages or the result of processing a message depends on the previous one
  - Running multiple consumers in one application
  - Long-time-taking handler

### Producer

[will be updated]

## Benchmark

[will be updated]

## Contributors

- [Alex Co](https://github.com/onimsha)
- [Duy Quach](https://github.com/quachduyy)
- [Phu Nguyen](https://github.com/phunguyen19)
- [Cuong Nguyen](https://github.com/CuongNgMan)

---
_Source: https://npm.io/package/@hoangthequyen/rd-kafka-node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
