四好公路
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
799 B

3 years ago
'use strict';
var util = require('util');
var Transform = require('stream').Transform;
var KafkaBuffer = require('../batch/KafkaBuffer');
var BrokerTransform = function (options) {
Transform.call(this, options);
this.noAckBatchSize = options ? options.noAckBatchSize : null;
this.noAckBatchAge = options ? options.noAckBatchAge : null;
this._KafkaBuffer = new KafkaBuffer(this.noAckBatchSize, this.noAckBatchAge);
};
util.inherits(BrokerTransform, Transform);
BrokerTransform.prototype._transform = function (chunk, enc, done) {
this._KafkaBuffer.addChunk(chunk, this._transformNext.bind(this));
done();
};
BrokerTransform.prototype._transformNext = function () {
this.push(this._KafkaBuffer.getBatch());
this._KafkaBuffer.truncateBatch();
};
module.exports = BrokerTransform;