kafka-provider
v1.0.3
Published
NodeJS dataverse Kafka Provider
Downloads
84
Maintainers
Readme
kafka-provider
KafkaJS Facade to use in dataverse NodeJS projects
Config
| Name | Description | | ------------------------------------------- | ---------------------------------------------------------------------------------------------- | | clientName | The name of the Kafka client | | brokers | An array of Kafka brokers with their ports | | connectionTimeout | Timeout value (ms) for the Kafka connection. Default value is 1000ms. The package trows error if the connection takes more than this value |
Usage
import KafkaClientProvider from 'kafka-provider';
import { KafkaConfig } from 'kafka-provider/src/types/kafka-config.interface';
import { Config as LoggerConfig } from 'commonjs-logger';
import {
appName,
kafkaBrokers,
kafkaClientName,
kafkaPassword,
kafkaUserName,
loggerLogLevel,
loggerLogStyle,
} from '../config/config';
const config: KafkaConfig = {
clientName: kafkaClientName,
brokers: kafkaBrokers,
};
const loggerConfig: LoggerConfig = {
logLevel: loggerLogLevel,
logStyle: loggerLogStyle,
appName: appName,
moduleName: 'KafkaProvider',
};
const provider = new KafkaClientProvider(config, kafkaUserName, kafkaPassword, loggerConfig);
export default provider;
// Initialize connection
import kafkaClient from './providers/kafkaConnect';
await kafkaClient.initializeConnections();
// Send events
await kafkaClient.sendBatch(topicName, messages);