-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
65 lines (56 loc) · 1.66 KB
/
index.ts
File metadata and controls
65 lines (56 loc) · 1.66 KB
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
62
63
///<reference path="index.d.ts"/>
/**
* Created by panzhichao on 16/8/2.
*/
'use strict';
import * as EventEmitter from 'events';
import {createClient, Client} from 'node-zookeeper-client';
import consumer from './src/Register';
import Service from './src/Service';
// let SERVICE_LENGTH = 0;
/**
* @param {Object} opt {conn:'zk.dev.pajkdc.com:2181',
* dubbo:{version:PZC,
* dversion:2.3.4.6,
* group:'xxx'},
* dependencies:{}}
* @constructor
*/
export default class NZD extends EventEmitter {
client: Client;
root: string;
dubboVersion: string;
application: { name: string };
private _consumer = consumer;
[serviceName: string]: any;
/**
* @param {Object} options 配置对象
* @param {Object} application
* @param {String} register
* @param {String} root
* @param {Object} dependencies
*/
constructor({
dubboVersion = '2.5.3',
application,
register,
root = 'dubbo',
}: NZDOptions, dependencies: Dependencies) {
super();
this.dubboVersion = dubboVersion;
this.application = application;
this.root = root;
this.client = createClient(register, {
sessionTimeout: 30000,
spinDelay: 1000,
retries: 5,
});
this.client.connect();
this.client.once('connected', () => {
Object.keys(dependencies).forEach(key => {
NZD.prototype[key] = new Service(this, dependencies[key], Object.keys(dependencies).length);
});
this._consumer(dependencies);
});
}
}