How to use the node-rdkafka.HighLevelProducer function in node-rdkafka

To help you get started, we’ve selected a few node-rdkafka examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Optum / knack / packages / knack-producer / knackHighLevelProducer.js View on Github external
const pEvent = require('p-event');
const Kafka = require('node-rdkafka');

const defaultOptions = {
	producerConfig: {
		'metadata.broker.list': ['localhost:9092']
	}
};

class KnackHighLevelProducer extends Kafka.HighLevelProducer {
	constructor(options = defaultOptions) {
		super(options.producerConfig);
		this._options = options;
	}

	get options() {
		return this._options;
	}

	async connect() {
		const connectEvent = pEvent(this, 'ready');
		super.connect();
		const connection = await Promise.resolve(connectEvent);
		return connection;
	}