🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

@kafka-ts/core

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kafka-ts/core

Core package for @kafka-ts

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

A wrapper of kafkajs for Node.JS.

Install

npm install --save @kafka-ts/core

# or

yarn add @kafka-ts/core

# or

pnpm add @kafka-ts/core

Usage

import { parseMessage, Partitioners, createKafkaClients } from '@kafka-ts/core';

(async function test() {
  const kafkaClients = await createKafkaClients({
    brokers: ['localhost:9092'],
  });

  const consumer = kafkaClients.client.consumer({
    groupId: 'test-id',
  });

  const producer = kafkaClients.client.producer({
    createPartitioner: Partitioners.LegacyPartitioner,
  });

  await Promise.all([consumer.connect(), producer.connect()]);

  await consumer.subscribe({
    topics: ['topic'],
    fromBeginning: true,
  });

  await consumer.run({
    eachBatch: async ({ batch }) => {
      const { messages } = batch;

      const rawMessages = messages.map((message) => {
        return parseMessage(message);
      });

      console.log(rawMessages);
    },
  });

  await producer.sendBatch({
    topicMessages: [
      {
        topic: 'topic',
        messages: [
          {
            value: 'hello from producer',
          },
        ],
      },
    ],
  });

  Promise.all(consumer.disconnect(), producer.disconnect());
})();

Keywords

kafka

FAQs

Package last updated on 13 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts