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

@hazeljs/kafka

v1.0.2

Published

Kafka module for HazelJS framework - produce, consume, and stream processing

Downloads

1,611

Readme

@hazeljs/kafka

Kafka Module for HazelJS - Produce, Consume, and Stream Processing

Apache Kafka integration for HazelJS with decorator-based consumers, producer service, and lightweight stream processing.

npm version npm downloads License: Apache-2.0

Features

  • Produce - Publish messages to Kafka topics via KafkaProducerService
  • Consume - Decorator-driven consumers with @KafkaConsumer and @KafkaSubscribe
  • Stream Processing - Lightweight KafkaStreamProcessor for consume-transform-produce pipelines
  • Graceful Shutdown - Clean disconnect on application shutdown
  • TypeScript - Full type safety with KafkaJS

Installation

npm install @hazeljs/kafka

Quick Start

1. Configure KafkaModule

// app.module.ts
import { HazelModule } from '@hazeljs/core';
import { KafkaModule } from '@hazeljs/kafka';

@HazelModule({
  imports: [
    KafkaModule.forRoot({
      clientId: 'my-app',
      brokers: ['localhost:9092'],
    }),
  ],
})
export class AppModule {}

2. Produce Messages

import { Injectable } from '@hazeljs/core';
import { KafkaProducerService } from '@hazeljs/kafka';

@Injectable()
export class OrderService {
  constructor(private producer: KafkaProducerService) {}

  async createOrder(data: CreateOrderDto) {
    await this.producer.send('orders', [{ key: data.id, value: JSON.stringify(data) }]);
    return data;
  }
}

3. Consume Messages (Decorator-Based)

import { Injectable } from '@hazeljs/core';
import { KafkaConsumer, KafkaSubscribe, KafkaMessagePayload } from '@hazeljs/kafka';

@KafkaConsumer({ groupId: 'order-processor' })
@Injectable()
export class OrderConsumer {
  @KafkaSubscribe('orders')
  async handleOrder({ message }: KafkaMessagePayload) {
    const order = JSON.parse(message.value!.toString());
    console.log('Processing order:', order);
  }
}

4. Register Consumers in Bootstrap

// index.ts
import { HazelApp, Container } from '@hazeljs/core';
import { KafkaModule } from '@hazeljs/kafka';
import { AppModule } from './app.module';
import { OrderConsumer } from './order.consumer';

async function bootstrap() {
  const app = new HazelApp(AppModule);

  // Register Kafka consumers
  const container = Container.getInstance();
  const orderConsumer = container.resolve(OrderConsumer);
  if (orderConsumer) {
    await KafkaModule.registerConsumersFromProvider(orderConsumer);
  }

  await app.listen(3000);
}
bootstrap();

Stream Processing

For consume-transform-produce pipelines:

import { Container } from '@hazeljs/core';
import { KafkaStreamProcessor } from '@hazeljs/kafka';

const container = Container.getInstance();
const processor = container.resolve(KafkaStreamProcessor);

processor
  .from('raw-events')
  .transform(async (msg) => ({
    value: JSON.stringify({ ...JSON.parse(msg.value!.toString()), enriched: true }),
  }))
  .to('enriched-events')
  .start();

Async Configuration

Use forRootAsync with ConfigService:

import { ConfigService } from '@hazeljs/config';
import { KafkaModule } from '@hazeljs/kafka';

KafkaModule.forRootAsync({
  useFactory: (config: ConfigService) => ({
    clientId: config.get('KAFKA_CLIENT_ID', 'my-app'),
    brokers: (config.get('KAFKA_BROKERS') || 'localhost:9092').toString().split(','),
  }),
  inject: [ConfigService],
});

API Reference

KafkaProducerService

  • send(topic, messages, options?) - Send message(s) to a topic
  • sendBatch(batch) - Send to multiple topics
  • isProducerConnected() - Check connection status

Decorators

  • @KafkaConsumer(options) - Mark class as consumer (groupId required)
  • @KafkaSubscribe(topic, options?) - Mark method as topic handler
    • fromBeginning?: boolean - Read from beginning of topic

KafkaStreamProcessor

  • from(topic) - Input topic
  • transform(fn) - Transform function (message) => output
  • to(topic) - Output topic
  • withGroupId(id) - Consumer group ID
  • start() - Start processing
  • stop() - Stop processing

Environment Variables

KAFKA_BROKERS=localhost:9092
KAFKA_CLIENT_ID=my-app

Requirements

  • Apache Kafka broker (>= 0.11.x)
  • Node.js >= 14