Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix: add callback to consumer.autoCommit method #198

Merged
merged 2 commits into from
Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# kafka-node CHANGELOG

## 2015-04-23, Version 0.2.26
- Fix: add callback to consumer.autoCommit method [#198](https://github.com/SOHU-Co/kafka-node/pull/198)
- Emit an error when there is a problem with the socket connection to the kafka broker [#196](https://github.com/SOHU-Co/kafka-node/pull/196)
- Fix: emit the error instead of slient swallow it [#193](https://github.com/SOHU-Co/kafka-node/pull/193)
- Typo in error message [#189](https://github.com/SOHU-Co/kafka-node/pull/189)

## 2015-04-01, Version 0.2.25
- Producer support `requireAcks` option [#187](https://github.com/SOHU-Co/kafka-node/pull/187)
- Update examples [#185](https://github.com/SOHU-Co/kafka-node/pull/185)
Expand Down
10 changes: 7 additions & 3 deletions lib/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,15 @@ Consumer.prototype.updateOffsets = function (topics, initing) {
}
});

if (this.options.autoCommit && !initing) this.autoCommit();
if (this.options.autoCommit && !initing) {
this.autoCommit(false, function (err) {
err && debug('auto commit offset', err);
});
}
};

function autoCommit(force, cb) {
if (this.committing && !force) return cb && cb('Offset committing');
if (this.committing && !force) return cb(null, 'Offset committing');

this.committing = true;
setTimeout(function () {
Expand All @@ -159,7 +163,7 @@ function autoCommit(force, cb) {
if (commits.length) {
this.client.sendOffsetCommitRequest(this.options.groupId, commits, cb);
} else {
cb && cb();
cb(null, 'Nothing to be committed');
}
}
Consumer.prototype.commit = Consumer.prototype.autoCommit = autoCommit;
Expand Down
10 changes: 7 additions & 3 deletions lib/highLevelConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,15 @@ HighLevelConsumer.prototype.updateOffsets = function (topics, initing) {
}
});

if (this.options.autoCommit && !initing) this.autoCommit();
if (this.options.autoCommit && !initing) {
this.autoCommit(false, function (err) {
err && debug('auto commit offset', err);
});
}
};

function autoCommit(force, cb) {
if (this.committing && !force) return cb && cb('Offset committing');
if (this.committing && !force) return cb(null, 'Offset committing');

this.committing = true;
setTimeout(function () {
Expand All @@ -468,7 +472,7 @@ function autoCommit(force, cb) {
if (commits.length) {
this.client.sendOffsetCommitRequest(this.options.groupId, commits, cb);
} else {
cb && cb();
cb(null, 'Nothing to be committed');
}
}
HighLevelConsumer.prototype.commit = HighLevelConsumer.prototype.autoCommit = autoCommit;
Expand Down