-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ListGroups and DescribeGroups protocol #770
Changes from 6 commits
00e9d82
513844d
d14d8e7
637eebd
d2d8957
6142335
7c950f0
ff929f6
20c7f97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,8 @@ const DEFAULTS = { | |
minTimeout: 1 * 1000, | ||
maxTimeout: 60 * 1000, | ||
randomize: true | ||
} | ||
}, | ||
maxAsyncRequests: 10 | ||
}; | ||
|
||
const KafkaClient = function (options) { | ||
|
@@ -413,6 +414,70 @@ KafkaClient.prototype.getApiVersions = function (broker, cb) { | |
broker.write(request); | ||
}; | ||
|
||
KafkaClient.prototype.getListGroups = function (callback) { | ||
if (!this.ready) { | ||
return callback(new Error('Client is not ready (getListGroups)')); | ||
} | ||
const brokers = this.brokerMetadata; | ||
async.mapValuesLimit(brokers, this.options.maxAsyncRequests, | ||
(brokerMetadata, brokerId, cb) => { | ||
const broker = this.brokerForLeader(brokerId); | ||
if (!broker || !broker.isConnected()) { | ||
return callback(new errors.BrokerNotAvailableError('Broker not available (getListGroups)')); | ||
} | ||
|
||
const correlationId = this.nextId(); | ||
const request = protocol.encodeListGroups(this.clientId, correlationId); | ||
this.queueCallback(broker.socket, correlationId, [protocol.decodeListGroups, cb]); | ||
broker.write(request); | ||
}, (err, results) => { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
// removing {error: null} before merging | ||
results = _.values(_.map(results, result => _.omitBy(result, _.isNull))); | ||
results.unshift({}); | ||
callback(null, _.merge.apply({}, results)); | ||
} | ||
); | ||
}; | ||
|
||
KafkaClient.prototype.getDescribeGroups = function (groups, callback) { | ||
if (!this.ready) { | ||
return callback(new Error('Client is not ready (getDescribeGroups)')); | ||
} | ||
|
||
async.groupBy(groups, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we use |
||
(group, cb) => { | ||
this.sendGroupCoordinatorRequest(group, (err, coordinator) => { | ||
cb(err || null, coordinator ? coordinator.coordinatorId : undefined); | ||
}); | ||
}, | ||
(err, results) => { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
|
||
async.mapValuesLimit(results, this.options.maxAsyncRequests, | ||
(groups, coordinator, cb) => { | ||
const broker = this.brokerForLeader(coordinator); | ||
if (!broker || !broker.isConnected()) { | ||
return callback(new errors.BrokerNotAvailableError('Broker not available (getDescribeGroups)')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
} | ||
|
||
const correlationId = this.nextId(); | ||
const request = protocol.encodeDescribeGroups(this.clientId, correlationId, groups); | ||
this.queueCallback(broker.socket, correlationId, [protocol.decodeDescribeGroups, cb]); | ||
broker.write(request); | ||
}, | ||
(err, res) => { | ||
callback(err || null, res); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we flatten the result so it's keyed by |
||
}); | ||
}); | ||
}; | ||
|
||
KafkaClient.prototype.close = function (callback) { | ||
logger.debug('close client'); | ||
this.closing = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callback
should becb
here.