How to use Kafkajs in ember?

I have installed kafkajs package using the command npm install kafkajs

but ember can’t found Kafka package.

I got this exception

Source Code

**const { Kafka } = require(‘kafkajs’)

const kafka = new Kafka({ clientId: ‘my-app’, brokers: [‘kafka1:9092’, ‘kafka2:9092’] })

const producer = kafka.producer() const consumer = kafka.consumer({ groupId: ‘test-group’ })

const run = async () => { // Producing await producer.connect() await producer.send({ topic: ‘test-topic’, messages: [ { value: ‘Hello KafkaJS user!’ }, ], })

// Consuming await consumer.connect() await consumer.subscribe({ topic: ‘test-topic’, fromBeginning: true })

await consumer.run({ eachMessage: async ({ topic, partition, message }) => { console.log({ partition, offset: message.offset, value: message.value.toString(), }) }, }) }**

Hi @PradeepKumar, welcome! I think you have a couple problems here.

The first is that until you’re using Embroider (which will soon be the default build pipeline) you’ll need to use ember-auto-import to import arbitrary js packages into an Ember app.

The second problem is that KafkaJS doesn’t seem to be usable in the context of a browser anyway, so even if you get the build pipeline part figured out it’s not going to work without something like an Electron shell, etc. For more information see the KafkaJS FAQ or github issues such as this one. There’s also a tutorial here with an example of using KafkaJS and then pairing it with a websocket client/server to push updates to the UI.