async unRegister(config) { assert(config && config.interfaceName, '[ZookeeperRegistry] unRegister(config) config.interfaceName is required'); assert(config.url, '[ZookeeperRegistry] unRegister(config) config.url is required'); const providerPath = this._buildProviderPath(config); const path = providerPath + '/' + urlencode.encode(config.url); this._registerMap.delete(path); await this._remove(path); }
encodeURIComponent(str) { return urlencode.encode(str, 'gbk'); }
async register(config) { assert(config && config.interfaceName, '[ZookeeperRegistry] register(config) config.interfaceName is required'); assert(config.url, '[ZookeeperRegistry] register(config) config.url is required'); const providerPath = this._buildProviderPath(config); await this._zkClient.mkdirp(providerPath); const path = providerPath + '/' + urlencode.encode(config.url); this._registerMap.set(path, config); try { // NOTE: Maybe the path is invalid, so remove it first if (await this._zkClient.exists(path)) { await this._remove(path); } await this._zkClient.create(path, EMPTY, this.options.ephemeralNode ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT); } catch (err) { if (err.name === 'NODE_EXISTS' && err.code === -110) { return; } throw err; } }
config.protocol || 'bolt', localIp, config.uniqueId || '', '1.0', process.pid, config.timeout, config.appName || '', Date.now()); const path = consumerPath + '/' + urlencode.encode(consumerUrl); this._zkClient.mkdirp(consumerPath) .then(() => {