@optum/knack-producer
v1.0.0
Published
A module for publishing to Apache Kafka.
Downloads
2
Keywords
Readme
Usage
first things first...
$ npm i @optum/knack-producer [email protected]
node-rdkafka
is now a peer dependency to give flexibility in versions
options
- producerConfig:
[Object]
librd producer config
Examples
const {
KnackProducer,
KnackHighLevelProducer
} = require("@optum/knack-producer");
const options = {
producerConfig: {
"metadata.broker.list": ["localhost:9092"]
}
};
// example data
const topic = "knack-test-topic-v1";
const key = Buffer.from("key-001");
const value = Buffer.from("hello from knack producer");
// use standard producer
const knackProducer = new KnackProducer(options);
await knackProducer.connect();
knackProducer.produce(topic, null, value, key, Date.now());
// use high level producer
const knackHighLevelProducer = new KnackHighLevelProducer(options);
await knackHighLevelProducer.connect();
producer.produceAsync(topic, null, value, key);
knackHighLevelProducer.produce(
topic,
null,
value,
key,
Date.now(),
(err, offset) => {
// The offset if our acknowledgement level allows us to receive delivery offsets
console.log(offset);
}
);