From ae16b827dd5bb0e438873ed128cacb3cadd6c965 Mon Sep 17 00:00:00 2001 From: Kun Tang Date: Thu, 14 Nov 2019 10:58:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E8=BF=9E?= =?UTF-8?q?=E4=B8=8D=E5=BA=94=E8=AF=A5=E6=B8=85=E7=A9=BA=E5=B7=B2=E6=9C=89?= =?UTF-8?q?=E7=9A=84provider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/dubbo/src/registry/zookeeper.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/dubbo/src/registry/zookeeper.ts b/packages/dubbo/src/registry/zookeeper.ts index 53fdc906..229fa20c 100644 --- a/packages/dubbo/src/registry/zookeeper.ts +++ b/packages/dubbo/src/registry/zookeeper.ts @@ -74,7 +74,10 @@ export class ZkRegistry extends Registry { //获取所有provider for (let inf of interfaces) { //init - this._dubboServiceUrlMap.set(inf, []); + // 重连进入init后不能清空已有provider, 会导致运行中的请求找到, 报no agents错误 + // 或者zk出现出错了, 无法获取provider, 那么之前获取的还能继续使用 + const providerList = []; + //this._dubboServiceUrlMap.set(inf, []); //当前接口在zookeeper中的路径 const dubboServicePath = `/${zkRoot}/${inf}/providers`; @@ -92,8 +95,10 @@ export class ZkRegistry extends Registry { for (let serviceUrl of dubboServiceUrls) { const url = DubboUrl.from(serviceUrl); - this._dubboServiceUrlMap.get(inf).push(url); + providerList.push(url); } + this._dubboServiceUrlMap.set(inf, providerList); + //写入consumer信息 this._createConsumer({ name: name, @@ -258,7 +263,9 @@ export class ZkRegistry extends Registry { return; } - const urls = dubboServiceUrls.map(serviceUrl => DubboUrl.from(serviceUrl)); + const urls = dubboServiceUrls.map(serviceUrl => + DubboUrl.from(serviceUrl), + ); if (urls.length === 0) { traceErr(new Error(`trigger watch ${e} agentList is empty`)); return; From 321428533295f7d88e6101c20ee15e2695352c0a Mon Sep 17 00:00:00 2001 From: Tkk Date: Fri, 15 Nov 2019 12:27:00 +0800 Subject: [PATCH 2/3] simplify code --- packages/dubbo/src/registry/zookeeper.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/dubbo/src/registry/zookeeper.ts b/packages/dubbo/src/registry/zookeeper.ts index 229fa20c..5fd3e4bd 100644 --- a/packages/dubbo/src/registry/zookeeper.ts +++ b/packages/dubbo/src/registry/zookeeper.ts @@ -76,7 +76,6 @@ export class ZkRegistry extends Registry { //init // 重连进入init后不能清空已有provider, 会导致运行中的请求找到, 报no agents错误 // 或者zk出现出错了, 无法获取provider, 那么之前获取的还能继续使用 - const providerList = []; //this._dubboServiceUrlMap.set(inf, []); //当前接口在zookeeper中的路径 @@ -93,11 +92,7 @@ export class ZkRegistry extends Registry { continue; } - for (let serviceUrl of dubboServiceUrls) { - const url = DubboUrl.from(serviceUrl); - providerList.push(url); - } - this._dubboServiceUrlMap.set(inf, providerList); + this._dubboServiceUrlMap.set(inf, dubboServiceUrls.map(serviceUrl => DubboUrl.from(serviceUrl))); //写入consumer信息 this._createConsumer({ From f465100d16b37a2fe94f6a86221b1c59a827e9da Mon Sep 17 00:00:00 2001 From: Tkk Date: Fri, 15 Nov 2019 12:29:52 +0800 Subject: [PATCH 3/3] keep code style --- packages/dubbo/src/registry/zookeeper.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/dubbo/src/registry/zookeeper.ts b/packages/dubbo/src/registry/zookeeper.ts index 5fd3e4bd..ebc5f870 100644 --- a/packages/dubbo/src/registry/zookeeper.ts +++ b/packages/dubbo/src/registry/zookeeper.ts @@ -258,9 +258,7 @@ export class ZkRegistry extends Registry { return; } - const urls = dubboServiceUrls.map(serviceUrl => - DubboUrl.from(serviceUrl), - ); + const urls = dubboServiceUrls.map(serviceUrl => DubboUrl.from(serviceUrl)); if (urls.length === 0) { traceErr(new Error(`trigger watch ${e} agentList is empty`)); return;