npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@biorate/kafkajs

v2.2.3

Published

KafkaJS connector

Readme

@biorate/kafkajs

KafkaJS connector suite — admin, producer (with Prometheus metrics), and consumer (with auto‑subscribe and batch processing) for Apache Kafka.

Features

  • Three connector classesKafkaJSAdminConnector, KafkaJSProducerConnector, KafkaJSConsumerConnector.
  • Prometheus metrics — counters and histograms for produce/consume operations (success/error, topic, partition, group).
  • Global configKafkaJSGlobal can be referenced via '#{KafkaJSGlobal}' string interpolation.
  • Consumer batching — configurable concurrency and chunk size.
  • Producer transactionstransaction() with automatic commit/abort.
  • Custom logging — routes KafkaJS log levels to console with proper severity.

Installation

pnpm add @biorate/kafkajs

Requires @biorate/connector, @biorate/inversion, @biorate/config, @biorate/prometheus, kafkajs, lodash-es.

Quick start

import { inject, container, Types, Core } from '@biorate/inversion';
import { IConfig, Config } from '@biorate/config';
import { KafkaJSProducerConnector } from '@biorate/kafkajs';

class Root extends Core() {
  @inject(KafkaJSProducerConnector) public producer: KafkaJSProducerConnector;
}

container.bind<IConfig>(Types.Config).to(Config).inSingletonScope();
container.bind<KafkaJSProducerConnector>(KafkaJSProducerConnector).toSelf().inSingletonScope();
container.bind<Root>(Root).toSelf().inSingletonScope();

container.get<IConfig>(Types.Config).merge({
  KafkaJSGlobal: { brokers: ['localhost:9092'], clientId: 'test-app', logLevel: 1 },
  KafkaJSProducer: [{ name: 'producer', global: '#{KafkaJSGlobal}' }],
});

(async () => {
  const root = container.get<Root>(Root);
  await root.$run();
  await root.producer.send('producer', {
    topic: 'test',
    messages: [{ key: 'key', value: 'hello' }],
  });
})();

API Reference

KafkaJSProducerConnector

| Member | Type | Description | |------------------|-------------------------------------------------|------------------------------------------| | namespace | 'KafkaJSProducer' | Config key. | | send(name, record) | (string, ProducerRecord) => Promise | Send messages with Prometheus tracking. | | transaction(name, record) | (string, ProducerRecord) => Promise | Send within a transaction (commit/abort on error). |

KafkaJSConsumerConnector

| Member | Type | Description | |---------------------|-------------------------------------------------------|---------------------------------------------------| | namespace | 'KafkaJSConsumer' | Config key. | | subscribe(name, handler) | (string, (messages, batch) => Promise<void>) | Subscribe to topics with chunked batch processing. | | unsubscribe(name) | (string) => Promise<void> | Disconnect consumer. |

KafkaJSAdminConnector

| Member | Type | Description | |--------------|----------------------------------------|--------------------| | namespace | 'KafkaJSAdmin' | Config key. |

Config

// Global config (referenced by name)
interface KafkaJSGlobal {
  brokers: string[];
  clientId: string;
  // ... KafkaConfig
}

// Producer
type IKafkaJSProducerConfig = IConnectorConfig & {
  global: KafkaConfig;
  options?: ProducerConfig;
  partitioner?: 'LegacyPartitioner' | 'DefaultPartitioner';
};

// Consumer
type IKafkaJSConsumerConfig = IConnectorConfig & {
  global: KafkaConfig;
  options: ConsumerConfig;
  subscribe?: ConsumerSubscribeTopics;
  runConfig?: ConsumerRunConfig;
  concurrency?: number;
};

// Admin
type IKafkaJSAdminConfig = IConnectorConfig & {
  global: KafkaConfig;
  options?: AdminConfig;
};

Metrics

| Metric | Type | Labels | |-------------------------------------|-----------|-----------------------------------------------------| | kafka_producer_seconds_count | Counter | topic, status | | kafka_producer_seconds | Histogram | topic, status | | kafka_consumer_count | Counter | topic, status, group, partition | | kafka_consumer_seconds | Histogram | topic, status, group, partition |

Errors

| Error | Condition | |------------------------------------|-------------------------------------------| | KafkaJSProducerCantConnectError | Producer connection fails. | | KafkaJSConsumerCantConnectError | Consumer connection fails. | | KafkaJSAdminCantConnectError | Admin client connection fails. |

Architecture

KafkaJS ──── connectors ──────────────────────────
│
├── KafkaJSProducerConnector
│   ├── namespace = 'KafkaJSProducer'
│   ├── connect() → Kafka.producer()
│   ├── send(name, record) → with Prometheus
│   ├── transaction(name, record) → commit/abort
│   └── metrics: counter + histogram (topic, status)
│
├── KafkaJSConsumerConnector
│   ├── namespace = 'KafkaJSConsumer'
│   ├── connect() → Kafka.consumer()
│   ├── subscribe(name, handler) → batch processing
│   │   └── chunks messages by concurrency
│   │   └── pause/resume per topic
│   │   └── counter + histogram per batch
│   └── unsubscribe(name) → disconnect
│
├── KafkaJSAdminConnector
│   ├── namespace = 'KafkaJSAdmin'
│   └── connect() → Kafka.admin()
│
└── LogCreator — custom logger for KafkaJS

Learn

  • Documentation can be found here - docs.

Release History

See the CHANGELOG

License

MIT