@biorate/kafkajs
TypeScript icon, indicating that this package has built-in type declarations

1.68.0 • Public • Published

KafkaJS

KafkaJS connector

Examples:

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 topic = 'test-kafkajs';
  const root = container.get<Root>(Root);
  await root.$run();
  await root.producer!.current!.send({
    topic,
    messages: [
      { key: 'key 1', value: 'hello world 1' },
      { key: 'key 2', value: 'hello world 2' },
      { key: 'key 3', value: 'hello world 3' },
    ],
  });
})();

Learn

  • Documentation can be found here - docs.

Release History

See the CHANGELOG

License

MIT

Copyright (c) 2021-present Leonid Levkin (llevkin)

Readme

Keywords

Package Sidebar

Install

npm i @biorate/kafkajs

Weekly Downloads

11

Version

1.68.0

License

MIT

Unpacked Size

327 kB

Total Files

80

Last publish

Collaborators

  • llevkin