-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathexample.js
executable file
·38 lines (31 loc) · 940 Bytes
/
example.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
/* eslint-disable no-bitwise,no-console */
const ZooKeeper = require('./lib/zookeeper');
function onCreate(client, rc, error, path) {
if (rc !== 0) {
console.log(`zk node create result: ${rc}, error: '${error}', path=${path}`);
} else {
console.log(`created zk node ${path}`);
process.nextTick(() => {
client.close();
});
}
}
function onConnect(client, err) {
if (err) {
throw err;
}
console.log(`zk session established, id=${client.client_id}`);
client.a_create('/node.js1', 'some value', ZooKeeper.ZOO_SEQUENCE | ZooKeeper.ZOO_EPHEMERAL, onCreate.bind(null, client));
}
const zk = new ZooKeeper({
connect: '127.0.0.1:2181',
timeout: 200000,
debug_level: ZooKeeper.ZOO_LOG_LEVEL_DEBUG,
host_order_deterministic: false,
});
zk.setLogger(console.log);
try {
zk.connect(onConnect.bind(null, zk));
} catch (e) {
console.error(e);
}