Skip to content

Commit 877eeb6

Browse files
edoardocomarwebmakersteve
authored andcommitted
fixes issue #58 (#59)
allows a topic name or a Kafka.Topic to be passed to Producer.produce developed with @mimaison
1 parent 5a51268 commit 877eeb6

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

lib/producer.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,26 +105,19 @@ function Producer(conf, topicConf) {
105105
}
106106

107107
/**
108-
* Create a topic if it does not exist. Otherwise, create it
108+
* Create a topic if it does not exist. Otherwise, get the cached one
109109
*
110110
* @private
111111
*/
112-
function maybeTopic(name, config) {
112+
function maybeTopic(name) {
113113
// create or get topic
114114
var topic;
115115

116116
if (typeof(name) === 'string') {
117-
118-
// If config is an empty object, reuse the ones we have in cache
119-
if (config) {
120-
topic = this.Topic(name, config);
117+
if (this.createdTopics[name]) {
118+
topic = this.createdTopics[name];
121119
} else {
122-
// if config is an empty object
123-
if (this.createdTopics[name]) {
124-
topic = this.createdTopics[name];
125-
} else {
126-
topic = this.createdTopics[name] = this.Topic(name, {});
127-
}
120+
topic = this.createdTopics[name] = this.Topic(name, {});
128121
}
129122

130123
return topic;
@@ -216,7 +209,7 @@ Producer.prototype.produce = function(topic, partition, message, key) {
216209
throw new Error('Producer not connected');
217210
}
218211

219-
if (typeof topic === 'object') {
212+
if (typeof topic === 'object' && !(topic instanceof Kafka.Topic)) {
220213
return this._produceObject(topic, partition);
221214
}
222215

@@ -229,7 +222,7 @@ Producer.prototype.produce = function(topic, partition, message, key) {
229222

230223
partition = partition == null ? this.defaultPartition : partition;
231224

232-
topic = maybeTopic.call(this, topic, false);
225+
topic = maybeTopic.call(this, topic);
233226

234227
return this._errorWrap(
235228
this._client.produce(topic, partition, message, key || null));

0 commit comments

Comments
 (0)