[go: up one dir, main page]

ts-kafka
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

ts-kafka

NOTE: This is a very opiniated library that uses a bunch of other internal libraries like gc-logger for Tracing and Logging support. We are planning to clean it up and open source it later.

A TypeScript wrapper service for the Kafka based on kafkaJs library from Confluent.

Publishing messages

import { Logger } from "@adhityan/gc-logger";
import { StreamingService } from "./src";

Logger.init({
    fileLoggerEnabled: false,
    serviceName: "test",
});

const stream = new StreamingService({
    connection: {
        brokers: ["pkc-l7pr2.ap-south-1.aws.confluent.cloud:9092"],
        sasl: {
            mechanism: "plain",
        },
        ssl: true,
    },
});

stream.publish("test", { value: '{"test":"ok"}' });

Subscribing to messages from a channel/subject

import { Logger } from "@adhityan/gc-logger";
import { Worker } from "./src";

Logger.init({
    fileLoggerEnabled: false,
    serviceName: "test",
});

@Worker({
    connection: {
        brokers: ["pkc-l7pr2.ap-south-1.aws.confluent.cloud:9092"],
        sasl: {
            mechanism: "plain",
        },
        ssl: true,
    },
    consumerOptions: {
        channel: "test",
        groupId: "test-consumer",
    },
})
class Test {
    public async messageReceived(message: any) {
        Logger.debug(message);
    }
}

new Test();

Readme

Keywords

none

Package Sidebar

Install

npm i ts-kafka

Weekly Downloads

0

Version

0.0.6

License

MIT

Unpacked Size

40.4 kB

Total Files

21

Last publish

Collaborators

  • adhityan