Kafka Please
This npm module lets you start up a Kafka broker (including ZooKeeper) locally.
It's meant to facilitate integration tests when you need to test against a Kafka broker.
You need Java in order to run Kafka. This npm module assumes that you already have Java installed.
Usage:
npm install kafka-please --save-dev
const makeKafkaServer = require('kafka-please');
makeKafkaServer().then(kafkaServer => {
console.log('made kafka server', kafkaServer);
console.log('zookeeper listens on', kafkaServer.zookeeperPort);
console.log('kafka listens on', kafkaServer.kafkaPort);
return kafkaServer.close().then(() => {
console.log('stopped kafka server');
return Promise.resolve();
});
});
Timeouts in mocha
Typically, starting a Kafka server takes ~2-3 seconds, and can make your
mocha tests time out, if you don't override the timeout:
describe('my integration test', () => {
it('should use kafka', function() {
this.timeout(60000);
});
});
Developing
- git clone this project
- run
fetch.sh
to download Kafka and unzip it - run
npm install
to get dependencies npm test
will run the integration tests.