Skip to content

Commit 02e2312

Browse files
committed
support buffer input
1 parent f58e375 commit 02e2312

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export class Producer extends Client {
226226
constructor(conf?: ProducerConfig, topicConfig?: TopicConfig);
227227

228228
public publish(message: string, topic?: string, partition?: number, key?: string, opaque?: string): Promise<DeliveryReport>;
229+
public publishBuffer(messageBuffer: Buffer, topic?: string, partition?: number, key?: string, opaque?: string): Promise<DeliveryReport>;
229230

230231
public report(): Observable<DeliveryReport>;
231232

src/producer.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,29 @@ class Producer extends KafkaClient {
6565
* @TODO will delivery report be synchronized with produce?
6666
*/
6767
publish(message, topic = this._config.topics[0], partition = -1, key = null, opaque = null) {
68+
// eslint-disable-next-line new-cap
69+
return this.publishBuffer(new Buffer.from(message), topic, partition, key, opaque);
70+
}
71+
72+
/**
73+
* Publish a message
74+
* @param {Buffer} messageBuffer - message buffer to send
75+
* @param {String} [topic=this._config.topics[0]] - topic to send to
76+
* @param {number} [partition=-1] - optionally specify a partition for the message, this defaults to -1 - which will
77+
* use librdkafka's default partitioner (consistent random for keyed messages, random for unkeyed messages)
78+
* @param {String} [key=null] - keyed message (optional)
79+
* @param {String} [opaque=null] - opaque token which gets passed along to your delivery reports
80+
* @return {Promise<DeliveryReport>}
81+
* @TODO will delivery report be synchronized with produce?
82+
*/
83+
publishBuffer(messageBuffer, topic = this._config.topics[0], partition = -1, key = null, opaque = null) {
6884
return new Promise((resolve, reject) => {
6985

7086
try {
7187
this.kafkaProducer.produce(
7288
topic,
7389
partition,
74-
// eslint-disable-next-line new-cap
75-
new Buffer.from(message),
90+
message,
7691
key,
7792
Date.now(),
7893
opaque

0 commit comments

Comments
 (0)