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 1/9] 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 2/9] 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 3/9] 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 4/9] 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 645c4f78ee2d4f23a30c3ac585666e6691679b9e Mon Sep 17 00:00:00 2001 From: kl Date: Mon, 1 Mar 2021 19:32:22 +0800 Subject: [PATCH 5/9] Added support for consul service discovery --- .../application-consul-discovery.properties | 6 ++ apollo-biz/pom.xml | 4 + .../src/test/resources/application.properties | 1 + .../controller/HomePageController.java | 2 +- .../service/ConsulDiscoveryService.java | 49 ++++++++++++ .../service/DefaultDiscoveryService.java | 2 +- .../application-consul-discovery.properties | 8 ++ .../service/ConsulDiscoveryServiceTest.java | 75 +++++++++++++++++++ 8 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 apollo-adminservice/src/main/resources/application-consul-discovery.properties create mode 100644 apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/ConsulDiscoveryService.java create mode 100644 apollo-configservice/src/main/resources/application-consul-discovery.properties create mode 100644 apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/ConsulDiscoveryServiceTest.java diff --git a/apollo-adminservice/src/main/resources/application-consul-discovery.properties b/apollo-adminservice/src/main/resources/application-consul-discovery.properties new file mode 100644 index 00000000000..ead17b1a876 --- /dev/null +++ b/apollo-adminservice/src/main/resources/application-consul-discovery.properties @@ -0,0 +1,6 @@ +eureka.client.enabled=false +#consul enabled +spring.cloud.consul.discovery.enabled=true +spring.cloud.consul.service-registry.enabled=true +spring.cloud.consul.discovery.heartbeat.enabled=true +spring.cloud.consul.discovery.instance-id=apollo-adminservice diff --git a/apollo-biz/pom.xml b/apollo-biz/pom.xml index 986e5ff1433..d98760b2e87 100644 --- a/apollo-biz/pom.xml +++ b/apollo-biz/pom.xml @@ -24,6 +24,10 @@ spring-cloud-starter-netflix-eureka-client + + org.springframework.cloud + spring-cloud-starter-consul-discovery + com.h2database h2 diff --git a/apollo-biz/src/test/resources/application.properties b/apollo-biz/src/test/resources/application.properties index 51fb02a6bee..0fbcdc145bc 100644 --- a/apollo-biz/src/test/resources/application.properties +++ b/apollo-biz/src/test/resources/application.properties @@ -3,3 +3,4 @@ spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.Ph spring.jpa.properties.hibernate.show_sql=false spring.h2.console.enabled = true spring.h2.console.settings.web-allow-others=true +spring.cloud.consul.discovery.enabled=false \ No newline at end of file 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 e5dd63c7be4..b3f7119331d 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","consul-discovery"}) @RestController public class HomePageController { private final DiscoveryService discoveryService; diff --git a/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/ConsulDiscoveryService.java b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/ConsulDiscoveryService.java new file mode 100644 index 00000000000..df0edb9aca5 --- /dev/null +++ b/apollo-configservice/src/main/java/com/ctrip/framework/apollo/metaservice/service/ConsulDiscoveryService.java @@ -0,0 +1,49 @@ +package com.ctrip.framework.apollo.metaservice.service; + +import com.ctrip.framework.apollo.core.dto.ServiceDTO; +import com.google.common.collect.Lists; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.consul.discovery.ConsulDiscoveryClient; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.List; + +/** + * @author : kl + * Service discovery consul implementation + **/ +@Service +@Profile({"consul-discovery"}) +public class ConsulDiscoveryService implements DiscoveryService { + + private final ConsulDiscoveryClient discoveryClient; + + public ConsulDiscoveryService(ConsulDiscoveryClient discoveryClient) { + this.discoveryClient = discoveryClient; + } + + + @Override + public List getServiceInstances(String serviceId) { + List instances = discoveryClient.getInstances(serviceId); + List serviceDTOList = Lists.newLinkedList(); + if (!CollectionUtils.isEmpty(instances)) { + instances.forEach(instance -> { + ServiceDTO serviceDTO = this.toServiceDTO(instance, serviceId); + serviceDTOList.add(serviceDTO); + }); + } + return serviceDTOList; + } + + private ServiceDTO toServiceDTO(ServiceInstance instance, String appName) { + ServiceDTO service = new ServiceDTO(); + service.setAppName(appName); + service.setInstanceId(instance.getInstanceId()); + String homePageUrl = "http://" + instance.getHost() + ":" + instance.getPort() + "/"; + service.setHomepageUrl(homePageUrl); + return service; + } +} 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 e142363b3a0..248f061a977 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","consul-discovery"}) public class DefaultDiscoveryService implements DiscoveryService { private final EurekaClient eurekaClient; diff --git a/apollo-configservice/src/main/resources/application-consul-discovery.properties b/apollo-configservice/src/main/resources/application-consul-discovery.properties new file mode 100644 index 00000000000..ba856ddaaf6 --- /dev/null +++ b/apollo-configservice/src/main/resources/application-consul-discovery.properties @@ -0,0 +1,8 @@ +apollo.eureka.server.enabled=false +eureka.client.enabled=false + +#consul enabled +spring.cloud.consul.discovery.enabled=true +spring.cloud.consul.service-registry.enabled=true +spring.cloud.consul.discovery.heartbeat.enabled=true +spring.cloud.consul.discovery.instance-id=apollo-configservice diff --git a/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/ConsulDiscoveryServiceTest.java b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/ConsulDiscoveryServiceTest.java new file mode 100644 index 00000000000..289bdcc12e3 --- /dev/null +++ b/apollo-configservice/src/test/java/com/ctrip/framework/apollo/metaservice/service/ConsulDiscoveryServiceTest.java @@ -0,0 +1,75 @@ +package com.ctrip.framework.apollo.metaservice.service; + +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 org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.consul.discovery.ConsulDiscoveryClient; + +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 2021/3/1 + */ +@RunWith(MockitoJUnitRunner.class) +public class ConsulDiscoveryServiceTest { + + @Mock + private ConsulDiscoveryClient consulDiscoveryClient; + + private ConsulDiscoveryService consulDiscoveryService; + + private String someServiceId; + + @Before + public void setUp() throws Exception { + consulDiscoveryService = new ConsulDiscoveryService(consulDiscoveryClient); + someServiceId = "someServiceId"; + } + + @Test + public void testGetServiceInstancesWithNullInstances() { + when(consulDiscoveryClient.getInstances(someServiceId)).thenReturn(null); + assertTrue(consulDiscoveryService.getServiceInstances(someServiceId).isEmpty()); + } + + + @Test + public void testGetServiceInstances() { + String someIp = "1.2.3.4"; + int somePort = 8080; + String someInstanceId = "someInstanceId"; + ServiceInstance someServiceInstance = mockServiceInstance(someInstanceId, someIp, somePort); + + when(consulDiscoveryClient.getInstances(someServiceId)).thenReturn( + Lists.newArrayList(someServiceInstance)); + + List serviceDTOList = consulDiscoveryService.getServiceInstances(someServiceId); + ServiceDTO serviceDTO = serviceDTOList.get(0); + assertEquals(1, serviceDTOList.size()); + assertEquals(someServiceId, serviceDTO.getAppName()); + assertEquals("http://1.2.3.4:8080/", serviceDTO.getHomepageUrl()); + + } + + private ServiceInstance mockServiceInstance(String instanceId, String ip, int port) { + ServiceInstance serviceInstance = mock(ServiceInstance.class); + when(serviceInstance.getInstanceId()).thenReturn(instanceId); + when(serviceInstance.getHost()).thenReturn(ip); + when(serviceInstance.getPort()).thenReturn(port); + + return serviceInstance; + } + + +} From e1bc99a36abd5e75a5a6fc1de2552574a0089efc Mon Sep 17 00:00:00 2001 From: kl Date: Mon, 1 Mar 2021 20:22:38 +0800 Subject: [PATCH 6/9] 1. Disable consul in eureka environment 2. Supplement the documents discovered by the consul service --- .../application-consul-discovery.properties | 1 + .../src/main/resources/application.yml | 3 +++ apollo-biz/src/test/resources/application.properties | 2 +- .../application-consul-discovery.properties | 1 + .../src/main/resources/application.yml | 5 +++-- docs/zh/deployment/distributed-deployment-guide.md | 12 ++++++++++++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apollo-adminservice/src/main/resources/application-consul-discovery.properties b/apollo-adminservice/src/main/resources/application-consul-discovery.properties index ead17b1a876..ab87bf1e8e8 100644 --- a/apollo-adminservice/src/main/resources/application-consul-discovery.properties +++ b/apollo-adminservice/src/main/resources/application-consul-discovery.properties @@ -1,5 +1,6 @@ eureka.client.enabled=false #consul enabled +spring.cloud.consul.enabled=true spring.cloud.consul.discovery.enabled=true spring.cloud.consul.service-registry.enabled=true spring.cloud.consul.discovery.heartbeat.enabled=true diff --git a/apollo-adminservice/src/main/resources/application.yml b/apollo-adminservice/src/main/resources/application.yml index ff5df0d7d6d..f497e2e8789 100644 --- a/apollo-adminservice/src/main/resources/application.yml +++ b/apollo-adminservice/src/main/resources/application.yml @@ -3,6 +3,9 @@ spring: name: apollo-adminservice profiles: active: ${apollo_profile} + cloud: + consul: + enabled: false ctrip: appid: 100003172 diff --git a/apollo-biz/src/test/resources/application.properties b/apollo-biz/src/test/resources/application.properties index 0fbcdc145bc..c5e5d2de78e 100644 --- a/apollo-biz/src/test/resources/application.properties +++ b/apollo-biz/src/test/resources/application.properties @@ -3,4 +3,4 @@ spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.Ph spring.jpa.properties.hibernate.show_sql=false spring.h2.console.enabled = true spring.h2.console.settings.web-allow-others=true -spring.cloud.consul.discovery.enabled=false \ No newline at end of file +spring.cloud.consul.enabled=false \ No newline at end of file diff --git a/apollo-configservice/src/main/resources/application-consul-discovery.properties b/apollo-configservice/src/main/resources/application-consul-discovery.properties index ba856ddaaf6..0aed7660f43 100644 --- a/apollo-configservice/src/main/resources/application-consul-discovery.properties +++ b/apollo-configservice/src/main/resources/application-consul-discovery.properties @@ -2,6 +2,7 @@ apollo.eureka.server.enabled=false eureka.client.enabled=false #consul enabled +spring.cloud.consul.enabled=true spring.cloud.consul.discovery.enabled=true spring.cloud.consul.service-registry.enabled=true spring.cloud.consul.discovery.heartbeat.enabled=true diff --git a/apollo-configservice/src/main/resources/application.yml b/apollo-configservice/src/main/resources/application.yml index aecb367c3f3..52c0a5299ae 100644 --- a/apollo-configservice/src/main/resources/application.yml +++ b/apollo-configservice/src/main/resources/application.yml @@ -3,7 +3,9 @@ spring: name: apollo-configservice profiles: active: ${apollo_profile} - + cloud: + consul: + enabled: false ctrip: appid: 100003171 @@ -31,7 +33,6 @@ eureka: healthcheck: enabled: true eurekaServiceUrlPollIntervalSeconds: 60 - management: health: status: diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index dfa525f7c68..8d34dec3cd9 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -442,6 +442,18 @@ mvn clean package -Pgithub,nacos-discovery -DskipTests -pl apollo-configservice, ```properties nacos.discovery.server-addr=127.0.0.1:8848 ``` +##### 2.2.1.2.8 启用外部Consul服务注册中心替换内置eureka + +1. 修改build.sh/build.bat,将config-service和admin-service的maven编译命令更改为 +```shell +mvn clean package -Pgithub -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github,consul-discovery -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password +``` + +2. 分别修改apollo-configservice和apollo-adminservice安装包中config目录下的application-github.properties,配置nacos服务器地址 +```properties +spring.cloud.consul.host=127.0.0.1 +spring.cloud.consul.port=8500 +``` ### 2.2.2 部署Apollo服务端 From 332f7fd927b6444f48249f30dda645c474c6ad62 Mon Sep 17 00:00:00 2001 From: kl Date: Mon, 1 Mar 2021 20:43:41 +0800 Subject: [PATCH 7/9] Disable consul for test cases --- apollo-adminservice/src/test/resources/application.properties | 1 + apollo-configservice/src/test/resources/application.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apollo-adminservice/src/test/resources/application.properties b/apollo-adminservice/src/test/resources/application.properties index 793e2b70b5f..b4cd6abd201 100644 --- a/apollo-adminservice/src/test/resources/application.properties +++ b/apollo-adminservice/src/test/resources/application.properties @@ -4,3 +4,4 @@ spring.jpa.properties.hibernate.show_sql=false spring.h2.console.enabled = true spring.h2.console.settings.web-allow-others=true spring.main.allow-bean-definition-overriding=true +spring.cloud.consul.enabled=false \ No newline at end of file diff --git a/apollo-configservice/src/test/resources/application.properties b/apollo-configservice/src/test/resources/application.properties index 959445d313e..01d0ae25e57 100644 --- a/apollo-configservice/src/test/resources/application.properties +++ b/apollo-configservice/src/test/resources/application.properties @@ -3,7 +3,7 @@ spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.Ph spring.h2.console.enabled = true spring.h2.console.settings.web-allow-others=true spring.jpa.properties.hibernate.show_sql=false - +spring.cloud.consul.enabled=false spring.main.allow-bean-definition-overriding=true # for ReleaseMessageScanner test From 42c241cfe1fc00941ce05544bb0642f70e56c093 Mon Sep 17 00:00:00 2001 From: kl Date: Mon, 1 Mar 2021 21:09:23 +0800 Subject: [PATCH 8/9] Code formatting adjustment --- .../apollo/metaservice/controller/HomePageController.java | 2 +- .../apollo/metaservice/service/DefaultDiscoveryService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 b3f7119331d..e5238eceef6 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","consul-discovery"}) +@Profile({"kubernetes", "nacos-discovery", "consul-discovery"}) @RestController public class HomePageController { private final DiscoveryService discoveryService; 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 248f061a977..adb0d8682b6 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","consul-discovery"}) +@ConditionalOnMissingProfile({"kubernetes", "nacos-discovery", "consul-discovery"}) public class DefaultDiscoveryService implements DiscoveryService { private final EurekaClient eurekaClient; From 9969c1c3a14db59c6d0cc717cc493a84b794302e Mon Sep 17 00:00:00 2001 From: chenkailing <632104866@qq.com> Date: Mon, 1 Mar 2021 23:05:23 +0800 Subject: [PATCH 9/9] Modify consul service discovery usage document --- docs/zh/deployment/distributed-deployment-guide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/zh/deployment/distributed-deployment-guide.md b/docs/zh/deployment/distributed-deployment-guide.md index 8d34dec3cd9..b9c93cfd7e6 100644 --- a/docs/zh/deployment/distributed-deployment-guide.md +++ b/docs/zh/deployment/distributed-deployment-guide.md @@ -449,7 +449,7 @@ nacos.discovery.server-addr=127.0.0.1:8848 mvn clean package -Pgithub -DskipTests -pl apollo-configservice,apollo-adminservice -am -Dapollo_profile=github,consul-discovery -Dspring_datasource_url=$apollo_config_db_url -Dspring_datasource_username=$apollo_config_db_username -Dspring_datasource_password=$apollo_config_db_password ``` -2. 分别修改apollo-configservice和apollo-adminservice安装包中config目录下的application-github.properties,配置nacos服务器地址 +2. 分别修改apollo-configservice和apollo-adminservice安装包中config目录下的application-github.properties,配置consul服务器地址 ```properties spring.cloud.consul.host=127.0.0.1 spring.cloud.consul.port=8500
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