Created
August 19, 2019 18:17
-
-
Save ThisIsMissEm/f819e4b89b1fe27c5c7c855f7c497ce6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Kafka, logLevel, KafkaConfig, SASLOptions } from "kafkajs"; | |
const options: KafkaConfig = { | |
clientId: "my-client", | |
brokers: (process.env.KAFKA_BROKERS && | |
process.env.KAFKA_BROKERS.split(",")) || ["localhost:9092"] | |
}; | |
if ( | |
process.env.KAFKA_AUTH_MECHANISM && | |
process.env.KAFKA_AUTH_USERNAME && | |
process.env.KAFKA_AUTH_PASSWORD | |
) { | |
let mechanism: string = "plain"; | |
switch (process.env.KAFKA_AUTH_MECHANISM) { | |
case "plain": | |
mechanism = "plain"; | |
break; | |
case "scram-sha-256": | |
mechanism = "scram-sha-256"; | |
break; | |
case "scram-sha-512": | |
mechanism = "scram-sha-256"; | |
break; | |
} | |
options.sasl = { | |
mechanism: mechanism, | |
username: process.env.KAFKA_AUTH_USERNAME, | |
password: process.env.KAFKA_AUTH_PASSWORD | |
}; | |
} | |
if (process.env.DEBUG && process.env.DEBUG.includes('kafka')) { | |
options.logLevel = logLevel.DEBUG; | |
} | |
export default new Kafka(options); | |
export interface Message { | |
id: string; | |
[propName: string]: any; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment