Kafka Client lib for Node.js & TypeScript developed by Superlógica Tecnologias S.A
To install the lib just run the command:
npm install @superlogica/super-kafka-client-js
Ready!
Now you can use the available interfaces, adapters and factories.
Start by creating a consumer:
import { makeConsumerMessageBroker, ConsumerType } from '@superlogica/super-kafka-client-js'
import { ExampleError } from './example-error'
import { ExampleMessageHandler } from './example-message-handler'
import { makeExampleService } from './example-service-factory'
const TOPIC = 'topic.name'
const GROUP_ID = `${process.env.APP_NAME}-consumer-group`
export class ConsumeExample {
static make(): ConsumerType {
const processMessage = new ExampleMessageHandler(
makeExampleService(),
)
return makeConsumerMessageBroker<ExampleMessageHandler.Message>(
{
topics: [TOPIC],
groupId: GROUP_ID,
directDqlErrors: [ExampleError]
},
processMessage
)
}
}
Or start by creating a producer:
import { makeProducerMessageBroker, ProducerType } from '@superlogica/super-kafka-client-js'
import { ExampleError } from './example-error'
import { ExampleMessageHandler } from './example-message-handler'
import { makeExampleService } from './example-service-factory'
const TOPIC = 'topic.name'
export class ProduceExample {
private static instance: ProducerType
static make(): ProducerType {
if (!this.instance) {
const processMessage = new ExampleMessageHandler()
this.instance = makeProducerMessageBroker(
{
topic: TOPIC
},
processMessage
)
}
return this.instance
}
}
Config vars
- APP_NAME (
broker:29092
) - KAFKA_SECURITY_PROTOCOL (
PLAINTEXT
) - KAFKA_SASL_MECHANISM (
PLAIN
) - KAFKA_SASL_USERNAME (
user
) - KAFKA_SASL_PASSWORD (
123
) - KAFKA_GROUP_ID (
${appConfig.name}-default-consumer-group
) - KAFKA_AUTO_OFFSET_RESET (
earliest
) - KAFKA_ENABLE_AUTO_COMMIT (
false
) - KAFKA_ENABLE_PARTITION_EOF (
true
) - APP_CONSUMERS (
NULL
) - KAFKA_LOG_MESSAGE_PAYLOAD (
false
) - CONNECT_KAFKA_LOCAL (
false
)