From fe75b4d3f2c824d4f6add524d67c55abc6796f84 Mon Sep 17 00:00:00 2001 From: kl <632104866@QQ.com> Date: Thu, 16 May 2019 11:07:18 +0800 Subject: [PATCH 01/16] add tech-support-qq-4.png --- doc/images/tech-support-qq-4.png | Bin 0 -> 7285 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/images/tech-support-qq-4.png diff --git a/doc/images/tech-support-qq-4.png b/doc/images/tech-support-qq-4.png new file mode 100644 index 0000000000000000000000000000000000000000..398a8c509bfe7c62ddba3b41593495eecce38b6d GIT binary patch literal 7285 zcmbtZ1yq#Zw#T4bhfWC@T0)ctVd##bLmKG@DFFo>7+Qt_iJ@D%L&PBj=?+0cx&=h) zef;0M_uX~h^{)5UTkFiM^X+wF?|t^!`?vRbtDz=Oh)0cwfq_A&s35C_fpLrH=7)0| zptLjDfiN&=#S~?wb$n-b<_TRvUa8$~m<|rgq&_B=-(kG0yC@RwkIznIO%_SGpxy_p z*!o-*U5F$+rexpHNM&|+d6Mc#{52+~rgy#;Qpqf#k*{bNTh`u8zK+D@!zYcDHh&y< z?oDskEvAK%Uf>eBc0D5Q0Zo5~!jXEPhmb;%K;Ari0KVRc6Q5uoie^H)+$Zja0?7|z$UjqTk%|L*1Gw^>mbqVP#SWMa|?pVq#zrXWy-?*T@ ze}hhM#T34nX_*a%{i)fyKfAlLa&+`M5}nBF{-HY40rM|Na+ zXr_T*zxHA69x8tvnZ^&1WOjEcOU6Cq9~SSH)dbZ>0~$ysy^)EV8J1mW4bUK(eUTR1 za+a-0K^aVNFHk&9f8_2fdD@J;Kk_>DnjLG0C1$sXJgUHQC5EYK&woXt;SZX+VUNaV zpRtJo@7&KgUUXzV2nXxBQ?MtD^N$;VVOL^$`|3Z}gFa%y4Ti$CvW1LU{&;q(DcPC4 z+C$%hBt^S(npb-Wb?!R(%KT9+5I&qc1RcR{mjNd|gf^d-x*a^R)&5e%zn&5%+(O#u z>?4US5PCw5J7c`%sQ=1z4I887x-pP{HJt3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2S{J&y9xz14BN)DATOG+`t+!b@X7 Date: Thu, 16 May 2019 11:13:55 +0800 Subject: [PATCH 02/16] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 83a9be9aea8..70e5f61fa93 100644 --- a/README.md +++ b/README.md @@ -115,12 +115,14 @@ Java客户端不依赖任何框架,能够运行于所有Java运行时环境, # Support - + + + From d7d3fd908dfd11113fd891b581c1ebf43c60eb1a Mon Sep 17 00:00:00 2001 From: kl Date: Fri, 11 Dec 2020 17:03:33 +0800 Subject: [PATCH 03/16] Enhance the user experience in the scenario of submitting duplicate keys --- .../txtresolver/PropertyResolver.java | 19 ++++++++++--------- .../directive/namespace-panel-directive.js | 1 - 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java index 89cdc9705da..bdea8b73666 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java @@ -8,6 +8,7 @@ import com.google.common.base.Strings; import org.springframework.stereotype.Component; +import javax.validation.constraints.NotNull; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -35,9 +36,9 @@ public ItemChangeSets resolve(long namespaceId, String configText, List oldKeyMapItem.remove(""); String[] newItems = configText.split(ITEM_SEPARATOR); - - if (isHasRepeatKey(newItems)) { - throw new BadRequestException("config text has repeat key please check."); + Set repeatKeys = new HashSet<>(); + if (isHasRepeatKey(newItems,repeatKeys)) { + throw new BadRequestException(String.format("config text has repeat key please check.repeat keys:%s", repeatKeys.toString())); } ItemChangeSets changeSets = new ItemChangeSets(); @@ -72,24 +73,24 @@ public ItemChangeSets resolve(long namespaceId, String configText, List return changeSets; } - private boolean isHasRepeatKey(String[] newItems) { + private boolean isHasRepeatKey(String[] newItems,@NotNull Set repeatKeys) { Set keys = new HashSet<>(); int lineCounter = 1; - int keyCount = 0; for (String item : newItems) { if (!isCommentItem(item) && !isBlankItem(item)) { - keyCount++; String[] kv = parseKeyValueFromItem(item); if (kv != null) { - keys.add(kv[0].toLowerCase()); + String key = kv[0].toLowerCase(); + if(!keys.add(key)){ + repeatKeys.add(key); + } } else { throw new BadRequestException("line:" + lineCounter + " key value must separate by '='"); } } lineCounter++; } - - return keyCount > keys.size(); + return !repeatKeys.isEmpty(); } private String[] parseKeyValueFromItem(String item) { diff --git a/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js b/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js index 66b5e46d0e3..7b4f88ae0cc 100644 --- a/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js +++ b/apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js @@ -745,7 +745,6 @@ function directive($window, $translate, toastr, AppUtil, EventManager, Permissio } ); namespace.commited = true; - toggleTextEditStatus(namespace); } function syntaxCheck(namespace) { From 5def448b7632b2992c7dda29c38750ff1368d0f9 Mon Sep 17 00:00:00 2001 From: chenkailing <632104866@qq.com> Date: Sat, 12 Dec 2020 14:16:43 +0800 Subject: [PATCH 04/16] Modify the key-value conflict exception prompt, adjust the code style --- .../portal/component/txtresolver/PropertyResolver.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java index bdea8b73666..10a614b69d1 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/txtresolver/PropertyResolver.java @@ -37,8 +37,8 @@ public ItemChangeSets resolve(long namespaceId, String configText, List String[] newItems = configText.split(ITEM_SEPARATOR); Set repeatKeys = new HashSet<>(); - if (isHasRepeatKey(newItems,repeatKeys)) { - throw new BadRequestException(String.format("config text has repeat key please check.repeat keys:%s", repeatKeys.toString())); + if (isHasRepeatKey(newItems, repeatKeys)) { + throw new BadRequestException(String.format("Config text has repeated keys: %s, please check your input.", repeatKeys.toString())); } ItemChangeSets changeSets = new ItemChangeSets(); @@ -73,7 +73,7 @@ public ItemChangeSets resolve(long namespaceId, String configText, List return changeSets; } - private boolean isHasRepeatKey(String[] newItems,@NotNull Set repeatKeys) { + private boolean isHasRepeatKey(String[] newItems, @NotNull Set repeatKeys) { Set keys = new HashSet<>(); int lineCounter = 1; for (String item : newItems) { From e12a48053da87ef0f13982483a3a82f65fb2ea9f Mon Sep 17 00:00:00 2001 From: chenkailing <632104866@qq.com> Date: Sat, 19 Dec 2020 18:37:05 +0800 Subject: [PATCH 05/16] Added nacos service discovery support --- apollo-adminservice/pom.xml | 4 ++ .../main/config/application-github.properties | 3 ++ .../application-nacosDiscovery.properties | 7 +++ apollo-configservice/pom.xml | 4 ++ .../main/config/application-github.properties | 3 ++ ...ontroller.java => HomePageController.java} | 8 +-- .../controller/ServiceController.java | 4 +- .../service/DefaultDiscoveryService.java | 2 +- .../service/NacosDiscoveryService.java | 53 +++++++++++++++++++ .../application-nacosDiscovery.properties | 8 +++ ...rTest.java => HomePageControllerTest.java} | 6 +-- .../controller/ServiceControllerTest.java | 2 +- .../distributed-deployment-guide.md | 16 ++++++ pom.xml | 6 +++ 14 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 apollo-adminservice/src/main/resources/application-nacosDiscovery.properties rename apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/{KubernetesHomePageController.java => HomePageController.java} (79%) create mode 100644 apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java create mode 100644 apollo-configservice/src/main/resources/application-nacosDiscovery.properties rename apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/{KubernetesHomePageControllerTest.java => HomePageControllerTest.java} (88%) diff --git a/apollo-adminservice/pom.xml b/apollo-adminservice/pom.xml index 6be4094df23..eaa4a6b0bd2 100644 --- a/apollo-adminservice/pom.xml +++ b/apollo-adminservice/pom.xml @@ -59,6 +59,10 @@ + + com.alibaba.boot + nacos-discovery-spring-boot-starter + com.h2database h2 diff --git a/apollo-adminservice/src/main/config/application-github.properties b/apollo-adminservice/src/main/config/application-github.properties index f4c35e6d289..a9742e1e9dd 100644 --- a/apollo-adminservice/src/main/config/application-github.properties +++ b/apollo-adminservice/src/main/config/application-github.properties @@ -2,3 +2,6 @@ spring.datasource.url = ${spring_datasource_url} spring.datasource.username = ${spring_datasource_username} spring.datasource.password = ${spring_datasource_password} + +#nacos discovery +#nacos.discovery.server-addr=127.0.0.1:8848 diff --git a/apollo-adminservice/src/main/resources/application-nacosDiscovery.properties b/apollo-adminservice/src/main/resources/application-nacosDiscovery.properties new file mode 100644 index 00000000000..657581c67b0 --- /dev/null +++ b/apollo-adminservice/src/main/resources/application-nacosDiscovery.properties @@ -0,0 +1,7 @@ +eureka.client.enabled=false +spring.cloud.discovery.enabled=false +#nacos enabled +nacos.discovery.register.enabled=true +nacos.discovery.auto-register=true +nacos.discovery.register.serviceName=apollo-adminservice +nacos.discovery.register.metadata.apollo.serviceName=apollo-adminservice diff --git a/apollo-configservice/pom.xml b/apollo-configservice/pom.xml index 52e4d12c41a..e1bbe3ab8ab 100644 --- a/apollo-configservice/pom.xml +++ b/apollo-configservice/pom.xml @@ -65,6 +65,10 @@ + + com.alibaba.boot + nacos-discovery-spring-boot-starter + com.h2database h2 diff --git a/apollo-configservice/src/main/config/application-github.properties b/apollo-configservice/src/main/config/application-github.properties index f4c35e6d289..a9742e1e9dd 100644 --- a/apollo-configservice/src/main/config/application-github.properties +++ b/apollo-configservice/src/main/config/application-github.properties @@ -2,3 +2,6 @@ spring.datasource.url = ${spring_datasource_url} spring.datasource.username = ${spring_datasource_username} spring.datasource.password = ${spring_datasource_password} + +#nacos discovery +#nacos.discovery.server-addr=127.0.0.1:8848 diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/KubernetesHomePageController.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java similarity index 79% rename from apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/KubernetesHomePageController.java rename to apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java index 1625cf9d062..0a215e2a20a 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/KubernetesHomePageController.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java @@ -11,14 +11,14 @@ /** - * For kubernetes discovery service, there is no eureka home page, so we need to add a default one + * For kubernetes,nacos discovery service, there is no eureka home page, so we need to add a default one */ -@Profile({"kubernetes"}) +@Profile({"kubernetes","nacosDiscovery"}) @RestController -public class KubernetesHomePageController { +public class HomePageController { private final DiscoveryService discoveryService; - public KubernetesHomePageController(DiscoveryService discoveryService) { + public HomePageController(DiscoveryService discoveryService) { this.discoveryService = discoveryService; } diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java index 808142a4333..d71c3e1e123 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java @@ -29,9 +29,7 @@ public List getMetaService() { } @RequestMapping("/config") - public List getConfigService( - @RequestParam(value = "appId", defaultValue = "") String appId, - @RequestParam(value = "ip", required = false) String clientIp) { + public List getConfigService() { return discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE); } diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java index 17d8a618bca..d724b587d40 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java @@ -17,7 +17,7 @@ * Default discovery service for Eureka */ @Service -@ConditionalOnMissingProfile({"kubernetes"}) +@ConditionalOnMissingProfile({"kubernetes","nacosDiscovery"}) public class DefaultDiscoveryService implements DiscoveryService { private final EurekaClient eurekaClient; diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java new file mode 100644 index 00000000000..032858244a0 --- /dev/null +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java @@ -0,0 +1,53 @@ +package com.ctrip.framework.apollo.metaservice.service; + +import com.alibaba.nacos.api.annotation.NacosInjected; +import com.alibaba.nacos.api.exception.NacosException; +import com.alibaba.nacos.api.naming.NamingService; +import com.alibaba.nacos.api.naming.pojo.Instance; +import com.ctrip.framework.apollo.core.dto.ServiceDTO; +import com.google.common.collect.Lists; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; + +import java.util.Collections; +import java.util.List; + +/** + * @author : kl + * Service discovery nacos implementation + **/ +@Service +@Profile({"nacosDiscovery"}) +public class NacosDiscoveryService implements DiscoveryService { + + private static final String SERVICE_NAME_METADATA_KEY = "apollo.serviceName"; + + @NacosInjected + private NamingService namingService; + + @Override + public List getServiceInstances(String serviceId) { + try { + List instances = namingService.getAllInstances(serviceId); + List serviceDTOList = Lists.newLinkedList(); + instances.forEach(instance -> { + ServiceDTO serviceDTO = this.toServiceDTO(instance); + serviceDTOList.add(serviceDTO); + }); + return serviceDTOList; + } catch (NacosException e) { + e.printStackTrace(); + } + return Collections.emptyList(); + } + + private ServiceDTO toServiceDTO(Instance instance) { + ServiceDTO service = new ServiceDTO(); + String appName = instance.getMetadata().get(SERVICE_NAME_METADATA_KEY); + service.setAppName(appName); + service.setInstanceId(instance.getInstanceId()); + String homePageUrl = "http://" + instance.getIp() + ":" + instance.getPort() + "/"; + service.setHomepageUrl(homePageUrl); + return service; + } +} diff --git a/apollo-configservice/src/main/resources/application-nacosDiscovery.properties b/apollo-configservice/src/main/resources/application-nacosDiscovery.properties new file mode 100644 index 00000000000..ea95b5275b5 --- /dev/null +++ b/apollo-configservice/src/main/resources/application-nacosDiscovery.properties @@ -0,0 +1,8 @@ +apollo.eureka.server.enabled=false +eureka.client.enabled=false +spring.cloud.discovery.enabled=false +#nacos enabled +nacos.discovery.register.enabled=true +nacos.discovery.auto-register=true +nacos.discovery.register.serviceName=apollo-configservice +nacos.discovery.register.metadata.apollo.serviceName=apollo-configservice diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/KubernetesHomePageControllerTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/HomePageControllerTest.java similarity index 88% rename from apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/KubernetesHomePageControllerTest.java rename to apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/HomePageControllerTest.java index 96a405e6910..42c0d1f548d 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/KubernetesHomePageControllerTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/HomePageControllerTest.java @@ -16,16 +16,16 @@ import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) -public class KubernetesHomePageControllerTest { +public class HomePageControllerTest { @Mock private DiscoveryService discoveryService; - private KubernetesHomePageController homePageController; + private HomePageController homePageController; @Before public void setUp() throws Exception { - homePageController = new KubernetesHomePageController(discoveryService); + homePageController = new HomePageController(discoveryService); } @Test diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/ServiceControllerTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/ServiceControllerTest.java index bebb4809a2a..7d2e2f4c079 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/ServiceControllerTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/ServiceControllerTest.java @@ -42,7 +42,7 @@ public void testGetConfigService() { when(discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE)) .thenReturn(someServices); - assertEquals(someServices, serviceController.getConfigService(someAppId, someClientIp)); + assertEquals(someServices, serviceController.getConfigService()); } @Test diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index d5d7297c068..03662b70489 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -522,6 +522,22 @@ pro.meta=http://apollo.xxx.com >注2: meta service地址也可以填入IP,0.11.0版本之前只支持填入一个IP。从0.11.0版本开始支持填入以逗号分隔的多个地址([PR #1214](https://github.com/ctripcorp/apollo/pull/1214)),如`http://1.1.1.1:8080,http://2.2.2.2:8080`,不过生产环境还是建议使用域名(走slb),因为机器扩容、缩容等都可能导致IP列表的变化。 +###### 2.2.1.1.2.5 启用外部nacos服务注册中心替换内置eureka +启用外部的nacos服务注册中心分两步走,configService和adminService的操作一样,如下: +- 1、修改VM options,激活nacosDiscovery的profile,如: +```shell +-Dapollo_profile=github,auth,nacosDiscovery +``` +- 2、前往application-github.properties配置nacos连接地址,如: +```properties +#nacos discovery +nacos.discovery.server-addr=127.0.0.1:8848 +``` +也可采用VM options的方式配置,如: +``` +-Dnacos.discovery.server-addr=127.0.0.1:8848 +``` + #### 2.2.1.2 通过源码构建 ##### 2.2.1.2.1 配置数据库连接信息 diff --git a/pom.xml b/pom.xml index 798d6c2e2c5..8ba4d0463a0 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,7 @@ 1.1.1 1.6.2 3.23.1-GA + 0.2.7 3.6.0 2.19.1 @@ -261,6 +262,11 @@ + + com.alibaba.boot + nacos-discovery-spring-boot-starter + ${nacos.discovery.version} + org.slf4j From da1b764fb1b02c35d69567588757e940cb85e52a Mon Sep 17 00:00:00 2001 From: kl Date: Mon, 21 Dec 2020 17:16:34 +0800 Subject: [PATCH 06/16] add NacosDiscoveryServiceTest.java --- apollo-adminservice/pom.xml | 4 - .../application-nacosDiscovery.properties | 3 +- apollo-biz/pom.xml | 4 + apollo-configservice/pom.xml | 4 - .../controller/HomePageController.java | 2 +- .../controller/ServiceController.java | 4 +- .../service/NacosDiscoveryService.java | 14 ++-- .../application-nacosDiscovery.properties | 3 +- .../controller/ServiceControllerTest.java | 2 +- .../service/NacosDiscoveryServiceTest.java | 80 +++++++++++++++++++ .../distributed-deployment-guide.md | 8 +- 11 files changed, 105 insertions(+), 23 deletions(-) create mode 100644 apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java diff --git a/apollo-adminservice/pom.xml b/apollo-adminservice/pom.xml index eaa4a6b0bd2..6be4094df23 100644 --- a/apollo-adminservice/pom.xml +++ b/apollo-adminservice/pom.xml @@ -59,10 +59,6 @@ - - com.alibaba.boot - nacos-discovery-spring-boot-starter - com.h2database h2 diff --git a/apollo-adminservice/src/main/resources/application-nacosDiscovery.properties b/apollo-adminservice/src/main/resources/application-nacosDiscovery.properties index 657581c67b0..27eefec6726 100644 --- a/apollo-adminservice/src/main/resources/application-nacosDiscovery.properties +++ b/apollo-adminservice/src/main/resources/application-nacosDiscovery.properties @@ -3,5 +3,4 @@ spring.cloud.discovery.enabled=false #nacos enabled nacos.discovery.register.enabled=true nacos.discovery.auto-register=true -nacos.discovery.register.serviceName=apollo-adminservice -nacos.discovery.register.metadata.apollo.serviceName=apollo-adminservice +nacos.discovery.register.service-name=apollo-adminservice diff --git a/apollo-biz/pom.xml b/apollo-biz/pom.xml index 986e5ff1433..cfabe71730d 100644 --- a/apollo-biz/pom.xml +++ b/apollo-biz/pom.xml @@ -24,6 +24,10 @@ spring-cloud-starter-netflix-eureka-client + + com.alibaba.boot + nacos-discovery-spring-boot-starter + com.h2database h2 diff --git a/apollo-configservice/pom.xml b/apollo-configservice/pom.xml index e1bbe3ab8ab..52e4d12c41a 100644 --- a/apollo-configservice/pom.xml +++ b/apollo-configservice/pom.xml @@ -65,10 +65,6 @@ - - com.alibaba.boot - nacos-discovery-spring-boot-starter - com.h2database h2 diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java index 0a215e2a20a..7fa1020f7e2 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java @@ -11,7 +11,7 @@ /** - * For kubernetes,nacos discovery service, there is no eureka home page, so we need to add a default one + * For non-eureka discovery services such as kubernetes and nacos, there is no eureka home page, so we need to add a default one */ @Profile({"kubernetes","nacosDiscovery"}) @RestController diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java index d71c3e1e123..84675fa066c 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java @@ -29,7 +29,9 @@ public List getMetaService() { } @RequestMapping("/config") - public List getConfigService() { + public List getConfigService( + @RequestParam(value = "appId", defaultValue = "") String appId, + @RequestParam(value = "ip", required = false) String clientIp) { return discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE); } diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java index 032858244a0..444f40ba8a3 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java @@ -20,18 +20,21 @@ @Profile({"nacosDiscovery"}) public class NacosDiscoveryService implements DiscoveryService { - private static final String SERVICE_NAME_METADATA_KEY = "apollo.serviceName"; - @NacosInjected private NamingService namingService; + @NacosInjected + public void setNamingService(NamingService namingService) { + this.namingService = namingService; + } + @Override public List getServiceInstances(String serviceId) { try { - List instances = namingService.getAllInstances(serviceId); + List instances = namingService.selectInstances(serviceId,true); List serviceDTOList = Lists.newLinkedList(); instances.forEach(instance -> { - ServiceDTO serviceDTO = this.toServiceDTO(instance); + ServiceDTO serviceDTO = this.toServiceDTO(instance, serviceId); serviceDTOList.add(serviceDTO); }); return serviceDTOList; @@ -41,9 +44,8 @@ public List getServiceInstances(String serviceId) { return Collections.emptyList(); } - private ServiceDTO toServiceDTO(Instance instance) { + private ServiceDTO toServiceDTO(Instance instance, String appName) { ServiceDTO service = new ServiceDTO(); - String appName = instance.getMetadata().get(SERVICE_NAME_METADATA_KEY); service.setAppName(appName); service.setInstanceId(instance.getInstanceId()); String homePageUrl = "http://" + instance.getIp() + ":" + instance.getPort() + "/"; diff --git a/apollo-configservice/src/main/resources/application-nacosDiscovery.properties b/apollo-configservice/src/main/resources/application-nacosDiscovery.properties index ea95b5275b5..7612bf4446e 100644 --- a/apollo-configservice/src/main/resources/application-nacosDiscovery.properties +++ b/apollo-configservice/src/main/resources/application-nacosDiscovery.properties @@ -4,5 +4,4 @@ spring.cloud.discovery.enabled=false #nacos enabled nacos.discovery.register.enabled=true nacos.discovery.auto-register=true -nacos.discovery.register.serviceName=apollo-configservice -nacos.discovery.register.metadata.apollo.serviceName=apollo-configservice +nacos.discovery.register.service-name=apollo-configservice diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/ServiceControllerTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/ServiceControllerTest.java index 7d2e2f4c079..bebb4809a2a 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/ServiceControllerTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/controller/ServiceControllerTest.java @@ -42,7 +42,7 @@ public void testGetConfigService() { when(discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE)) .thenReturn(someServices); - assertEquals(someServices, serviceController.getConfigService()); + assertEquals(someServices, serviceController.getConfigService(someAppId, someClientIp)); } @Test diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java new file mode 100644 index 00000000000..54bcfb1779c --- /dev/null +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java @@ -0,0 +1,80 @@ +package com.ctrip.framework.apollo.metaservice.service; + +import com.alibaba.nacos.api.naming.pojo.Instance; +import com.alibaba.nacos.client.naming.NacosNamingService; +import com.ctrip.framework.apollo.core.dto.ServiceDTO; +import com.google.common.collect.Lists; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * @author kl (http://kailing.pub) + * @since 2020/12/21 + */ +@RunWith(MockitoJUnitRunner.class) +public class NacosDiscoveryServiceTest { + + private NacosDiscoveryService nacosDiscoveryService; + + @Mock + private NacosNamingService nacosNamingService; + + private String someServiceId; + + + @Before + public void setUp() throws Exception { + nacosDiscoveryService = new NacosDiscoveryService(); + nacosDiscoveryService.setNamingService(nacosNamingService); + someServiceId = "someServiceId"; + } + + @Test + public void testGetServiceInstancesWithEmptyInstances() throws Exception { + assertTrue(nacosNamingService.selectInstances(someServiceId, true).isEmpty()); + } + + + @Test + public void testGetServiceInstancesWithInvalidServiceId() { + assertTrue(nacosDiscoveryService.getServiceInstances(someServiceId).isEmpty()); + } + + @Test + public void testGetServiceInstances() throws Exception { + String someIp = "1.2.3.4"; + int somePort = 8080; + String someInstanceId = "someInstanceId"; + Instance someServiceInstance = mockServiceInstance(someServiceId, someInstanceId, + someIp,somePort); + + when(nacosNamingService.selectInstances(someServiceId,true)).thenReturn( + Lists.newArrayList(someServiceInstance)); + + List serviceDTOList = nacosDiscoveryService.getServiceInstances(someServiceId); + + assertEquals(1, serviceDTOList.size()); + assertEquals(serviceDTOList.get(0).getHomepageUrl(),"http://1.2.3.4:8080/"); + + } + + private Instance mockServiceInstance(String serviceId, String instanceId, String ip, int port) { + Instance serviceInstance = mock(Instance.class); + when(serviceInstance.getServiceName()).thenReturn(serviceId); + when(serviceInstance.getInstanceId()).thenReturn(instanceId); + when(serviceInstance.getIp()).thenReturn(ip); + when(serviceInstance.getPort()).thenReturn(port); + + return serviceInstance; + } + +} diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index 03662b70489..659f3d11f44 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -526,9 +526,13 @@ pro.meta=http://apollo.xxx.com 启用外部的nacos服务注册中心分两步走,configService和adminService的操作一样,如下: - 1、修改VM options,激活nacosDiscovery的profile,如: ```shell --Dapollo_profile=github,auth,nacosDiscovery +-Dapollo_profile=github,nacosDiscovery ``` -- 2、前往application-github.properties配置nacos连接地址,如: +也可采用环境变量配置方式激活配置,如: +```shell +export SPRING_PROFILES_ACTIVE=github,nacosDiscovery +``` +- 2、前往`config`目录下的`application-github.properties`文件配置nacos连接地址,如: ```properties #nacos discovery nacos.discovery.server-addr=127.0.0.1:8848 From 02b65cbc7f421e22efd312759b784db989e47693 Mon Sep 17 00:00:00 2001 From: kl Date: Mon, 21 Dec 2020 17:29:54 +0800 Subject: [PATCH 07/16] use logger print Nacosxception --- .../apollo/metaservice/service/NacosDiscoveryService.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java index 444f40ba8a3..aee893bdea1 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java @@ -6,6 +6,8 @@ import com.alibaba.nacos.api.naming.pojo.Instance; import com.ctrip.framework.apollo.core.dto.ServiceDTO; import com.google.common.collect.Lists; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; @@ -20,6 +22,7 @@ @Profile({"nacosDiscovery"}) public class NacosDiscoveryService implements DiscoveryService { + private final static Logger logger = LoggerFactory.getLogger(NacosDiscoveryService.class); private NamingService namingService; @@ -38,8 +41,8 @@ public List getServiceInstances(String serviceId) { serviceDTOList.add(serviceDTO); }); return serviceDTOList; - } catch (NacosException e) { - e.printStackTrace(); + } catch (NacosException ex) { + logger.error(ex.getMessage(),ex); } return Collections.emptyList(); } From 6ecfbe63ef708989bbc5c522f6a8cc411df53e49 Mon Sep 17 00:00:00 2001 From: kl Date: Mon, 21 Dec 2020 17:59:45 +0800 Subject: [PATCH 08/16] Fix UnnecessaryStubbingException thrown by NacosDiscoveryServiceTest --- .../service/NacosDiscoveryServiceTest.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java index 54bcfb1779c..9f490b43ced 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java @@ -9,6 +9,7 @@ import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; + import java.util.List; import static org.junit.Assert.assertEquals; @@ -54,22 +55,21 @@ public void testGetServiceInstances() throws Exception { String someIp = "1.2.3.4"; int somePort = 8080; String someInstanceId = "someInstanceId"; - Instance someServiceInstance = mockServiceInstance(someServiceId, someInstanceId, - someIp,somePort); + Instance someServiceInstance = mockServiceInstance(someInstanceId, someIp, somePort); - when(nacosNamingService.selectInstances(someServiceId,true)).thenReturn( + when(nacosNamingService.selectInstances(someServiceId, true)).thenReturn( Lists.newArrayList(someServiceInstance)); List serviceDTOList = nacosDiscoveryService.getServiceInstances(someServiceId); - + ServiceDTO serviceDTO = serviceDTOList.get(0); assertEquals(1, serviceDTOList.size()); - assertEquals(serviceDTOList.get(0).getHomepageUrl(),"http://1.2.3.4:8080/"); + assertEquals(someServiceId, serviceDTO.getAppName()); + assertEquals("http://1.2.3.4:8080/", serviceDTO.getHomepageUrl()); } - private Instance mockServiceInstance(String serviceId, String instanceId, String ip, int port) { + private Instance mockServiceInstance(String instanceId, String ip, int port) { Instance serviceInstance = mock(Instance.class); - when(serviceInstance.getServiceName()).thenReturn(serviceId); when(serviceInstance.getInstanceId()).thenReturn(instanceId); when(serviceInstance.getIp()).thenReturn(ip); when(serviceInstance.getPort()).thenReturn(port); From 03f6e354c8157afdbd1edf984321a03691f89429 Mon Sep 17 00:00:00 2001 From: chenkailing <632104866@qq.com> Date: Mon, 21 Dec 2020 22:09:41 +0800 Subject: [PATCH 09/16] Nacosdiscovery is disabled by default --- .../src/main/config/application-github.properties | 1 + .../src/main/config/application-github.properties | 1 + docs/zh/deployment/distributed-deployment-guide.md | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apollo-adminservice/src/main/config/application-github.properties b/apollo-adminservice/src/main/config/application-github.properties index a9742e1e9dd..52bf59649db 100644 --- a/apollo-adminservice/src/main/config/application-github.properties +++ b/apollo-adminservice/src/main/config/application-github.properties @@ -4,4 +4,5 @@ spring.datasource.username = ${spring_datasource_username} spring.datasource.password = ${spring_datasource_password} #nacos discovery +nacos.discovery.enabled=false #nacos.discovery.server-addr=127.0.0.1:8848 diff --git a/apollo-configservice/src/main/config/application-github.properties b/apollo-configservice/src/main/config/application-github.properties index a9742e1e9dd..52bf59649db 100644 --- a/apollo-configservice/src/main/config/application-github.properties +++ b/apollo-configservice/src/main/config/application-github.properties @@ -4,4 +4,5 @@ spring.datasource.username = ${spring_datasource_username} spring.datasource.password = ${spring_datasource_password} #nacos discovery +nacos.discovery.enabled=false #nacos.discovery.server-addr=127.0.0.1:8848 diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index 659f3d11f44..4aa1e2262b3 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -532,14 +532,15 @@ pro.meta=http://apollo.xxx.com ```shell export SPRING_PROFILES_ACTIVE=github,nacosDiscovery ``` -- 2、前往`config`目录下的`application-github.properties`文件配置nacos连接地址,如: +- 2、前往`config`目录下的`application-github.properties`文件配置nacos,如: ```properties #nacos discovery +nacos.discovery.enabled=true nacos.discovery.server-addr=127.0.0.1:8848 ``` 也可采用VM options的方式配置,如: ``` --Dnacos.discovery.server-addr=127.0.0.1:8848 +-Dnacos.discovery.enabled=true -Dnacos.discovery.server-addr=127.0.0.1:8848 ``` #### 2.2.1.2 通过源码构建 From bdc9a5b591d87209ba7d08fe16385b2d80ed4649 Mon Sep 17 00:00:00 2001 From: chenkailing <632104866@qq.com> Date: Wed, 30 Dec 2020 00:02:01 +0800 Subject: [PATCH 10/16] Isolate nacos service discovery dependencies through maven profile --- apollo-adminservice/pom.xml | 17 +++++++++++ .../main/config/application-github.properties | 4 --- apollo-biz/pom.xml | 6 ++-- apollo-configservice/pom.xml | 22 +++++++++++++++ .../main/config/application-github.properties | 4 --- .../service/NacosDiscoveryServiceTest.java | 4 +-- pom.xml | 28 +++++++++++++++---- 7 files changed, 65 insertions(+), 20 deletions(-) diff --git a/apollo-adminservice/pom.xml b/apollo-adminservice/pom.xml index 6be4094df23..c704f3b683b 100644 --- a/apollo-adminservice/pom.xml +++ b/apollo-adminservice/pom.xml @@ -139,4 +139,21 @@ + + + + nacos-discovery + + + com.alibaba.boot + nacos-discovery-spring-boot-starter + + + com.alibaba + fastjson + + + + + diff --git a/apollo-adminservice/src/main/config/application-github.properties b/apollo-adminservice/src/main/config/application-github.properties index 52bf59649db..f4c35e6d289 100644 --- a/apollo-adminservice/src/main/config/application-github.properties +++ b/apollo-adminservice/src/main/config/application-github.properties @@ -2,7 +2,3 @@ spring.datasource.url = ${spring_datasource_url} spring.datasource.username = ${spring_datasource_username} spring.datasource.password = ${spring_datasource_password} - -#nacos discovery -nacos.discovery.enabled=false -#nacos.discovery.server-addr=127.0.0.1:8848 diff --git a/apollo-biz/pom.xml b/apollo-biz/pom.xml index cfabe71730d..1a44e1a404f 100644 --- a/apollo-biz/pom.xml +++ b/apollo-biz/pom.xml @@ -24,14 +24,12 @@ spring-cloud-starter-netflix-eureka-client - - com.alibaba.boot - nacos-discovery-spring-boot-starter - + com.h2database h2 test + diff --git a/apollo-configservice/pom.xml b/apollo-configservice/pom.xml index 52e4d12c41a..cc240a8e154 100644 --- a/apollo-configservice/pom.xml +++ b/apollo-configservice/pom.xml @@ -65,6 +65,11 @@ + + com.alibaba.nacos + nacos-api + ${nacos-discovery-api.version} + com.h2database h2 @@ -145,4 +150,21 @@ + + + + nacos-discovery + + + com.alibaba.boot + nacos-discovery-spring-boot-starter + + + com.alibaba + fastjson + + + + + diff --git a/apollo-configservice/src/main/config/application-github.properties b/apollo-configservice/src/main/config/application-github.properties index 52bf59649db..f4c35e6d289 100644 --- a/apollo-configservice/src/main/config/application-github.properties +++ b/apollo-configservice/src/main/config/application-github.properties @@ -2,7 +2,3 @@ spring.datasource.url = ${spring_datasource_url} spring.datasource.username = ${spring_datasource_username} spring.datasource.password = ${spring_datasource_password} - -#nacos discovery -nacos.discovery.enabled=false -#nacos.discovery.server-addr=127.0.0.1:8848 diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java index 9f490b43ced..3f01e7f134e 100644 --- a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryServiceTest.java @@ -1,7 +1,7 @@ package com.ctrip.framework.apollo.metaservice.service; +import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; -import com.alibaba.nacos.client.naming.NacosNamingService; import com.ctrip.framework.apollo.core.dto.ServiceDTO; import com.google.common.collect.Lists; import org.junit.Before; @@ -27,7 +27,7 @@ public class NacosDiscoveryServiceTest { private NacosDiscoveryService nacosDiscoveryService; @Mock - private NacosNamingService nacosNamingService; + private NamingService nacosNamingService; private String someServiceId; diff --git a/pom.xml b/pom.xml index 8ba4d0463a0..0bda40cce6b 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ 1.1.1 1.6.2 3.23.1-GA - 0.2.7 + 1.4.0 3.6.0 2.19.1 @@ -262,11 +262,6 @@ - - com.alibaba.boot - nacos-discovery-spring-boot-starter - ${nacos.discovery.version} - org.slf4j @@ -821,6 +816,27 @@ + + nacos-discovery + + 0.2.7 + 1.2.75 + + + + + com.alibaba.boot + nacos-discovery-spring-boot-starter + ${nacos.discovery.version} + + + com.alibaba + fastjson + ${fastjson.version} + + + + ctrip-logging From 1cfe1e0f26187365f86e9e458b36b2356b8a7911 Mon Sep 17 00:00:00 2001 From: chenkailing <632104866@qq.com> Date: Sat, 2 Jan 2021 20:57:56 +0800 Subject: [PATCH 11/16] Modify the nacos service discovery activation naming style --- apollo-biz/pom.xml | 2 -- .../controller/HomePageController.java | 2 +- .../controller/ServiceController.java | 4 +-- .../service/DefaultDiscoveryService.java | 2 +- .../service/NacosDiscoveryService.java | 2 +- ...=> application-nacos-discovery.properties} | 0 .../distributed-deployment-guide.md | 35 +++++++------------ 7 files changed, 18 insertions(+), 29 deletions(-) rename apollo-configservice/src/main/resources/{application-nacosDiscovery.properties => application-nacos-discovery.properties} (100%) diff --git a/apollo-biz/pom.xml b/apollo-biz/pom.xml index 1a44e1a404f..986e5ff1433 100644 --- a/apollo-biz/pom.xml +++ b/apollo-biz/pom.xml @@ -24,12 +24,10 @@ spring-cloud-starter-netflix-eureka-client - com.h2database h2 test - diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java index 7fa1020f7e2..5ead5fddcad 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java @@ -13,7 +13,7 @@ /** * For non-eureka discovery services such as kubernetes and nacos, there is no eureka home page, so we need to add a default one */ -@Profile({"kubernetes","nacosDiscovery"}) +@Profile({"kubernetes","nacos-discovery"}) @RestController public class HomePageController { private final DiscoveryService discoveryService; diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java index 84675fa066c..808142a4333 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/ServiceController.java @@ -30,8 +30,8 @@ public List getMetaService() { @RequestMapping("/config") public List getConfigService( - @RequestParam(value = "appId", defaultValue = "") String appId, - @RequestParam(value = "ip", required = false) String clientIp) { + @RequestParam(value = "appId", defaultValue = "") String appId, + @RequestParam(value = "ip", required = false) String clientIp) { return discoveryService.getServiceInstances(ServiceNameConsts.APOLLO_CONFIGSERVICE); } diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java index d724b587d40..aa7b0dc6f12 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java @@ -17,7 +17,7 @@ * Default discovery service for Eureka */ @Service -@ConditionalOnMissingProfile({"kubernetes","nacosDiscovery"}) +@ConditionalOnMissingProfile({"kubernetes","nacos-discovery"}) public class DefaultDiscoveryService implements DiscoveryService { private final EurekaClient eurekaClient; diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java index aee893bdea1..19f4629fb9e 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/NacosDiscoveryService.java @@ -19,7 +19,7 @@ * Service discovery nacos implementation **/ @Service -@Profile({"nacosDiscovery"}) +@Profile({"nacos-discovery"}) public class NacosDiscoveryService implements DiscoveryService { private final static Logger logger = LoggerFactory.getLogger(NacosDiscoveryService.class); diff --git a/apollo-configservice/src/main/resources/application-nacosDiscovery.properties b/apollo-configservice/src/main/resources/application-nacos-discovery.properties similarity index 100% rename from apollo-configservice/src/main/resources/application-nacosDiscovery.properties rename to apollo-configservice/src/main/resources/application-nacos-discovery.properties diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index 4aa1e2262b3..6213fa15ab3 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -522,27 +522,6 @@ pro.meta=http://apollo.xxx.com >注2: meta service地址也可以填入IP,0.11.0版本之前只支持填入一个IP。从0.11.0版本开始支持填入以逗号分隔的多个地址([PR #1214](https://github.com/ctripcorp/apollo/pull/1214)),如`http://1.1.1.1:8080,http://2.2.2.2:8080`,不过生产环境还是建议使用域名(走slb),因为机器扩容、缩容等都可能导致IP列表的变化。 -###### 2.2.1.1.2.5 启用外部nacos服务注册中心替换内置eureka -启用外部的nacos服务注册中心分两步走,configService和adminService的操作一样,如下: -- 1、修改VM options,激活nacosDiscovery的profile,如: -```shell --Dapollo_profile=github,nacosDiscovery -``` -也可采用环境变量配置方式激活配置,如: -```shell -export SPRING_PROFILES_ACTIVE=github,nacosDiscovery -``` -- 2、前往`config`目录下的`application-github.properties`文件配置nacos,如: -```properties -#nacos discovery -nacos.discovery.enabled=true -nacos.discovery.server-addr=127.0.0.1:8848 -``` -也可采用VM options的方式配置,如: -``` --Dnacos.discovery.enabled=true -Dnacos.discovery.server-addr=127.0.0.1:8848 -``` - #### 2.2.1.2 通过源码构建 ##### 2.2.1.2.1 配置数据库连接信息 @@ -624,7 +603,19 @@ META_SERVERS_OPTS="-Ddev_meta=$dev_meta -Dfat_meta=$fat_meta -Duat_meta=$uat_met 位于`apollo-portal/target/`目录下的`apollo-portal-x.x.x-github.zip` -### 2.2.2 部署Apollo服务端 +启用外部nacos服务注册中心替换内置eureka + +##### 2.2.1.2.7 启用外部nacos服务注册中心替换内置eureka + +1.修改build.sh,将maven命令更改为 +```shell +mvn clean package -Pgithub,nacos-discovery -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github,nacos-discovery -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password + +``` +2.在config目录下修改application-github.properties,添加nacos服务器地址 +```properties +nacos.discovery.server-addr=127.0.0.1:8848 +``` #### 2.2.2.1 部署apollo-configservice 将对应环境的`apollo-configservice-x.x.x-github.zip`上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh. From 3262be4a61ad61dbd1d0f76cd0817beaedd4539b Mon Sep 17 00:00:00 2001 From: chenkailing <632104866@qq.com> Date: Sat, 2 Jan 2021 23:24:31 +0800 Subject: [PATCH 12/16] Modify nacos service discovery usage document --- docs/zh/deployment/distributed-deployment-guide.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index 6213fa15ab3..993f4029d85 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -603,20 +603,20 @@ META_SERVERS_OPTS="-Ddev_meta=$dev_meta -Dfat_meta=$fat_meta -Duat_meta=$uat_met 位于`apollo-portal/target/`目录下的`apollo-portal-x.x.x-github.zip` -启用外部nacos服务注册中心替换内置eureka - ##### 2.2.1.2.7 启用外部nacos服务注册中心替换内置eureka -1.修改build.sh,将maven命令更改为 +1.修改build.sh,/build.bat,将config-service和admin-service的maven编译命令更改为 ```shell mvn clean package -Pgithub,nacos-discovery -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github,nacos-discovery -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password ``` -2.在config目录下修改application-github.properties,添加nacos服务器地址 +2.在config目录下修改application-github.properties,配置nacos服务器地址 ```properties nacos.discovery.server-addr=127.0.0.1:8848 ``` +### 2.2.2 部署Apollo服务端 + #### 2.2.2.1 部署apollo-configservice 将对应环境的`apollo-configservice-x.x.x-github.zip`上传到服务器上,解压后执行scripts/startup.sh即可。如需停止服务,执行scripts/shutdown.sh. From 1a87aeae5683f26833c3aed8963c360d508f9a12 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sun, 3 Jan 2021 10:07:53 +0800 Subject: [PATCH 13/16] Update distributed-deployment-guide.md --- docs/zh/deployment/distributed-deployment-guide.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index 993f4029d85..a706d31f012 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -605,11 +605,11 @@ META_SERVERS_OPTS="-Ddev_meta=$dev_meta -Dfat_meta=$fat_meta -Duat_meta=$uat_met ##### 2.2.1.2.7 启用外部nacos服务注册中心替换内置eureka -1.修改build.sh,/build.bat,将config-service和admin-service的maven编译命令更改为 +1.修改build.sh/build.bat,将config-service和admin-service的maven编译命令更改为 ```shell mvn clean package -Pgithub,nacos-discovery -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github,nacos-discovery -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password - ``` + 2.在config目录下修改application-github.properties,配置nacos服务器地址 ```properties nacos.discovery.server-addr=127.0.0.1:8848 @@ -1194,4 +1194,4 @@ config: # 三、Portal 实现用户登录功能 -请参考[Portal 实现用户登录功能](zh/development/portal-how-to-implement-user-login-function) \ No newline at end of file +请参考[Portal 实现用户登录功能](zh/development/portal-how-to-implement-user-login-function) From 0e308dffe84a0f74f7aa0f61f5b017bcdbd5df89 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sun, 3 Jan 2021 10:08:47 +0800 Subject: [PATCH 14/16] Update HomePageController.java --- .../apollo/metaservice/controller/HomePageController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java index 5ead5fddcad..e5dd63c7be4 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/controller/HomePageController.java @@ -13,7 +13,7 @@ /** * For non-eureka discovery services such as kubernetes and nacos, there is no eureka home page, so we need to add a default one */ -@Profile({"kubernetes","nacos-discovery"}) +@Profile({"kubernetes", "nacos-discovery"}) @RestController public class HomePageController { private final DiscoveryService discoveryService; From fa710d26cc8e3f1e166e8a36958e70ee55179740 Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sun, 3 Jan 2021 10:09:18 +0800 Subject: [PATCH 15/16] Update DefaultDiscoveryService.java --- .../apollo/metaservice/service/DefaultDiscoveryService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java index aa7b0dc6f12..e142363b3a0 100644 --- a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/DefaultDiscoveryService.java @@ -17,7 +17,7 @@ * Default discovery service for Eureka */ @Service -@ConditionalOnMissingProfile({"kubernetes","nacos-discovery"}) +@ConditionalOnMissingProfile({"kubernetes", "nacos-discovery"}) public class DefaultDiscoveryService implements DiscoveryService { private final EurekaClient eurekaClient; From 4af2656e4d9d5c690b086e1f1a9c8c36b9b25fec Mon Sep 17 00:00:00 2001 From: Jason Song Date: Sun, 3 Jan 2021 10:11:05 +0800 Subject: [PATCH 16/16] Update distributed-deployment-guide.md --- docs/zh/deployment/distributed-deployment-guide.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index a706d31f012..df2c2859a92 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -605,12 +605,12 @@ META_SERVERS_OPTS="-Ddev_meta=$dev_meta -Dfat_meta=$fat_meta -Duat_meta=$uat_met ##### 2.2.1.2.7 启用外部nacos服务注册中心替换内置eureka -1.修改build.sh/build.bat,将config-service和admin-service的maven编译命令更改为 +1. 修改build.sh/build.bat,将config-service和admin-service的maven编译命令更改为 ```shell mvn clean package -Pgithub,nacos-discovery -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github,nacos-discovery -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password ``` -2.在config目录下修改application-github.properties,配置nacos服务器地址 +2. 在config目录下修改application-github.properties,配置nacos服务器地址 ```properties nacos.discovery.server-addr=127.0.0.1:8848 ```
Apollo配置中心技术支持③群
群号:742035428
Apollo配置中心技术支持④群
群号:516773934
Apollo配置中心技术支持③群
群号:742035428(已满)
Apollo配置中心技术支持②群
群号:904287263(已满)
Apollo配置中心技术支持①群
群号:375526581(已满)
tech-support-qq-4 tech-support-qq-3 tech-support-qq-2 tech-support-qq-1