@@ -65,14 +65,29 @@ class Producer extends KafkaClient {
65
65
* @TODO will delivery report be synchronized with produce?
66
66
*/
67
67
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 ) {
68
84
return new Promise ( ( resolve , reject ) => {
69
85
70
86
try {
71
87
this . kafkaProducer . produce (
72
88
topic ,
73
89
partition ,
74
- // eslint-disable-next-line new-cap
75
- new Buffer . from ( message ) ,
90
+ message ,
76
91
key ,
77
92
Date . now ( ) ,
78
93
opaque
0 commit comments