Kafka-Penguin
Current standard
Last updated
Was this helpful?
Current standard
Last updated
Was this helpful?
Was this helpful?
const { Kafka } = require('kafkajs')
require('dotenv').config();
// Create the client with the broker list
const kafka = new Kafka({
clientId: 'fail-fast-producer',
brokers: [],
ssl: true,
sasl: {
mechanism: 'plain',
username: 'username',
password: 'password',
},
})
module.exports = kafka;const kafkaPenguin = require('kafka-penguin')
//Import your kafkajs client from another file
const devClient = require('./clientConfig.js')
const strategies = penguinjs.failfast
// Initialize strategy-- passing in the # of retries and your kafkjs client
const newStrategy = new strategies.FailFast(2, devClient)
//Create a wrong topic message
const message = {
topic: 'wrong-topic',
messages: [
{key: "hello",
value: "world",
}
]
}
// Initialize producer from the failfast strategy
const producer = newStrategy.producer();
producer.connect()
.then(() => console.log('Connected!'))
.then(() => producer.send(message))
.catch((e: any) => console.log("error: ", e.message))