Skip to content

Commit ae6525d

Browse files
committed
Make AdminClient inherit from Client
1 parent d6a9638 commit ae6525d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/admin.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ var Client = require('./client');
4848
var util = require('util');
4949
var Kafka = require('../librdkafka');
5050
var LibrdKafkaError = require('./error');
51-
var shallowCopy = require('./util').shallowCopy;
51+
var { shallowCopy, bindingVersion } = require('./util');
52+
53+
util.inherits(AdminClient, Client);
5254

5355
/**
5456
* Create a new AdminClient for making topics, partitions, and more.
@@ -108,7 +110,7 @@ function AdminClient(conf) {
108110
* for the topic.
109111
*/
110112

111-
this._client = new Kafka.AdminClient(conf);
113+
Client.call(this, conf, Kafka.AdminClient);
112114
this._isConnected = false;
113115
this.globalConfig = conf;
114116
}
@@ -122,6 +124,7 @@ function AdminClient(conf) {
122124
* Unlike the other connect methods, this one is synchronous.
123125
*/
124126
AdminClient.prototype.connect = function () {
127+
this._client.configureCallbacks(true, this._cb_configs);
125128
LibrdKafkaError.wrap(this._client.connect(), true);
126129
this._isConnected = true;
127130
};
@@ -135,6 +138,9 @@ AdminClient.prototype.connect = function () {
135138
AdminClient.prototype.disconnect = function () {
136139
LibrdKafkaError.wrap(this._client.disconnect(), true);
137140
this._isConnected = false;
141+
// The AdminClient doesn't provide a callback. So we can't
142+
// wait for completion.
143+
this._client.configureCallbacks(false, this._cb_configs);
138144
};
139145

140146
/**

src/admin.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ void AdminClient::Init(v8::Local<v8::Object> exports) {
8282
tpl->SetClassName(Nan::New("AdminClient").ToLocalChecked());
8383
tpl->InstanceTemplate()->SetInternalFieldCount(1);
8484

85+
// Inherited from NodeKafka::Connection
86+
Nan::SetPrototypeMethod(tpl, "configureCallbacks", NodeConfigureCallbacks);
87+
8588
// Admin client operations
8689
Nan::SetPrototypeMethod(tpl, "createTopic", NodeCreateTopic);
8790
Nan::SetPrototypeMethod(tpl, "deleteTopic", NodeDeleteTopic);

0 commit comments

Comments
 (0)