This repository has been archived by the owner on Jan 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.js
61 lines (54 loc) · 1.99 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var assert = require('assert')
var os = require('os')
var async = require('async')
var inherits = require('util').inherits
var EventEmitter = require('events').EventEmitter
var path = require('path')
var Stream = require('stream')
var RingList = require('./ring-list')()
var noop = function () {}
var nullLogger = {}
Object.keys(console).forEach(function (f) { nullLogger[f] = noop })
function setLogger(logger) {
if (logger) {
var required = Object.keys(console)
assert.ok(
required.every(
function (f) {
return typeof(logger[f] === 'function')
}
),
'logger must implement the global.console interface'
)
return logger
}
else {
return nullLogger
}
}
module.exports = function (options) {
var logger = setLogger(options.logger)
var Client = require('./client')(logger)
var Consumer = require('./consumer')(logger, inherits, EventEmitter, RingList)
var Producer = require('./producer')(logger, inherits, RingList)
var Broker = require('./broker')(logger, inherits, EventEmitter, Client)
var BrokerPool = require('./broker-pool')(logger, inherits, EventEmitter)
var Partition = require('./partition')(logger, inherits, EventEmitter, Broker)
var PartitionSet = require('./partition-set')(logger, inherits, EventEmitter, Consumer, Producer)
var MessageBuffer = require('./message-buffer')(inherits, EventEmitter)
var Topic = require('./topic')(logger, inherits, Stream, MessageBuffer, Partition, PartitionSet)
var StaticConnector = require('./static-connector')(logger, inherits, EventEmitter, Broker)
if (options.zookeeper) {
try {
var ZooKeeper = require('zkjs')
var ZK = require('./zk')(logger, async, inherits, EventEmitter, path, ZooKeeper)
var ZKConnector = require('./zkconnector')(logger, async, inherits, EventEmitter, ZK, Broker)
}
catch (e) {
logger.error('zkjs could not be loaded')
throw e
}
}
var Kafka = require('./kafka')(inherits, EventEmitter, os, BrokerPool, Topic, ZKConnector, StaticConnector, Client.compression)
return new Kafka(options)
}