Class KafkaJSProducerConnector

Description

KafkaJS producer connector

Features:

  • producer connector manager for KafkaJS

Example

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' },
],
});
})();

Hierarchy

Constructors

Properties

#connections: Map<string, Producer>

Description

Private connections storage

#connections: Map<string, Producer> = ...

Description

Private connections storage

#current: Producer

Description

Private link to selected (used) connection

#current: Producer = undefined

Description

Private link to selected (used) connection

config: IConfig

Description

Config dependency

counter: Counter

Description

Counter

histogram: Histogram

Description

Histogram

namespace: "KafkaJSProducer" = 'KafkaJSProducer'

Description

Namespace path for fetching configuration

Accessors

Methods

Generated using TypeDoc