1.7.0 • Published 10 months ago

@xnestjs/kafka v1.7.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@xnestjs/kafka

NestJS extension library for Apache Kafka

Install

npm install @xnestjs/kafka
# or using yarn
yarn add @xnestjs/kafka

Usage

Register sync

An example of nestjs module that import the @xnestjs/kafka

// module.ts
import { Module } from '@nestjs/common';
import { KafkaModule } from '@xnestjs/kafka';

@Module({
    imports: [
        KafkaModule.forRoot({
            useValue: {
                brokers: ['localhost'],
            },
        }),
    ],
})
export class MyModule {
}

Register async

An example of nestjs module that import the @xnestjs/kafka async

// module.ts
import { Module } from '@nestjs/common';
import { KafkaModule } from '@xnestjs/kafka';

@Module({
    imports: [
        KafkaModule.forRootAsync({
            inject: [ConfigModule],
            useFactory: (config: ConfigService) => ({
                brokers: config.get('KAFKA_BROKERS'),
            }),
        }),
    ]
})
export class MyModule {
}

Environment Variables

The library supports configuration through environment variables. Environment variables below is accepted. All environment variables starts with prefix (KAFKA_). This can be configured while registering the module.

<--- BEGIN env --->

Environment VariableTypeDefaultDescription
KAFKA_BROKERSString[]!localhostHost names of Kafka brokers
KAFKA_CONSUMER_GROUP_IDStringkafka_default_group
KAFKA_CLIENT_IDString
KAFKA_SASLEnumDefines the SASL Mechanism. Accepted values are (plain, scram-sha-256, scram-sha-512, aws)
KAFKA_SSLBooleanFalseEnabled the SSL connection
KAFKA_SSL_CA_CERTStringOptionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla's CAs are completely replaced when CAs are explicitly specified using this option.
KAFKA_SSL_CERT_FILEStringThe File that contains Cert chains in PEM format.
KAFKA_SSL_KEY_FILEStringThe File that contains private keys in PEM format.
KAFKA_SSL_KEY_PASSPHRASEStringPFX or PKCS12 encoded private key and certificate chain.
KAFKA_SSL_REJECT_UNAUTHORIZEDBooleanIf true the server will reject any connection which is notauthorized with the list of supplied CAs. This option only has an effect if requestCert is true.
KAFKA_CONNECT_TIMEOUTNumber
KAFKA_AUTH_TIMEOUTNumber
KAFKA_REAUTH_THRESHOLDNumber
KAFKA_REQUEST_TIMEOUTNumber
KAFKA_ENFORCE_REQUEST_TIMEOUTNumber
KAFKA_RETRIESNumber
KAFKA_RETRY_MAX_TIMENumber
KAFKA_RETRY_INITIAL_TIMENumber

SASL Environment Variables

The environment variables are available when KAFKA_SASL is one of plain, scram-sha-256 or scram-sha-512

Environment VariableTypeDefaultDescription
KAFKA_SASL_USERNAMEString!Username
KAFKA_SASL_PASSWORDString!Password

The environment variables are available when KAFKA_SASL is aws

Environment VariableTypeDefaultDescription
AWS_AUTH_IDENTITYString!
AWS_ACCESS_KEY_IDString!
AWS_SECRET_ACCESS_KEYString!
AWS_SESSION_TOKENString

<--- END env --->

1.7.0

10 months ago

1.6.4

10 months ago

1.6.3

10 months ago

1.6.2

10 months ago

1.5.3

10 months ago

1.6.1

10 months ago

1.5.2

10 months ago

1.6.0

10 months ago

1.2.6

10 months ago

1.5.1

10 months ago

1.2.4

10 months ago

1.5.0

10 months ago

1.3.1

10 months ago

1.2.0

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.1.0

11 months ago

1.0.1

1 year ago

0.10.4

1 year ago

0.10.0

1 year ago