@superlogica/super-kafka-client-js
v1.3.0
Published
Kafka Client Lib with segregated interfaces developed with clean architecture concepts by Superlógica Tecnologias S.A
Downloads
44
Readme
What is Super Kafka Client?
Kafka Client lib for Node.js & TypeScript developed by Superlógica Tecnologias S.A
Getting started
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.
How Works?
Create Kafka Consumer
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
}
}
ENV Vars
You will need to configure some environment variables. If they are not provided, the following default values will be used.
| Name | Default Value |
|---------------------------------|--------------------------------------------|
| 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 |