1.3.0 • Published 1 year ago

@superlogica/super-kafka-client-js v1.3.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Super Kafka Client JS

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.

NameDefault Value
APP_NAMEbroker:29092
KAFKA_SECURITY_PROTOCOLPLAINTEXT
KAFKA_SASL_MECHANISMPLAIN
KAFKA_SASL_USERNAMEuser
KAFKA_SASL_PASSWORD123
KAFKA_GROUP_ID${appConfig.name}-default-consumer-group
KAFKA_AUTO_OFFSET_RESETearliest
KAFKA_ENABLE_AUTO_COMMITfalse
KAFKA_ENABLE_PARTITION_EOFtrue
APP_CONSUMERSNULL
KAFKA_LOG_MESSAGE_PAYLOADfalse
1.3.0

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

2 years ago