赞
踩
Client(Java应用端)通过域名访问Meta Server获取Config Service服务列表(IP+Port),而后直接通过IP+Port访问服务,同时在Client侧会做load balance、错误重试
准备Apollo域名
- <dependency>
- <groupId>com.ctrip.framework.apollo</groupId>
- <artifactId>apollo-client</artifactId>
- <version>1.5.1.7</version>
- </dependency>
- <dependency>
- <groupId>com.ctrip.framework.apollo</groupId>
- <artifactId>apollo-core</artifactId>
- <version>1.5.1.7</version>
- </dependency>
- //相对来说重要、用来匹配配置数据
- app.id=vx-tms-order
- apollo.bootstrap.enabled=true
- apollo.bootstrap.eagerLoad.enabled=true
- apollo.bootstrap.namespaces=application.properties
- //对应的ip地址也需要找运维要一个,否则本地拉不到
- dev.meta=http://40.73.114.140:8040/
- @EnableApolloConfig
- @SpringBootApplication
- public class OrderApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(OrderApplication.class, args);
- }
-
- }
- 2022-07-27 19:24:45.405 WARN 18980 --- [ngPollService-1] c.c.f.a.i.RemoteConfigLongPollService : Long polling failed, will retry in 2 seconds. appId: vx-tms-app, cluster: default, namespaces: application.properties, long polling url: null, reason: Get config services failed from http://apollo.meta/services/config?appId=vx-tms-app&ip=10.92.33.45 [Cause: Could not complete get operation [Cause: apollo.meta]]
- 2022-07-27 19:24:47.424 WARN 18980 --- [ main] c.c.f.a.i.AbstractConfigRepository : Sync config failed, will retry. Repository class com.ctrip.framework.apollo.internals.RemoteConfigRepository, reason: Get config services failed from http://apollo.meta/services/config?appId=vx-tms-app&ip=10.92.33.45 [Cause: Could not complete get operation [Cause: apollo.meta]]
- 2022-07-27 19:24:49.443 WARN 18980 --- [ngPollService-1] c.c.f.a.i.RemoteConfigLongPollService : Long polling failed, will retry in 4 seconds. appId: vx-tms-app, cluster: default, namespaces: application.properties+application, long polling url: null, reason: Get config services failed from http://apollo.meta/services/config?appId=vx-tms-app&ip=10.92.33.45 [Cause: Could not complete get operation [Cause: apollo.meta]]
-
- 1、是SpringCloud项目、并且没有包含spring-cloud-starter-bootstrap 则需要引入pom
-
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-bootstrap</artifactId>
- </dependency>
-
- 2、引入了本地还爆读不到配置,则再检查是不是读取不到 apollo-env.properties
- PS:(目前这个问题没找到原因,替代方案是 在idea的启动命令里,配置上 -Denv=dev)
2、本地能读取apollo的pom包,但是部署时,取不到、报错如下
- 2022-07-27 19:24:45.405 WARN 18980 --- [ngPollService-1] c.c.f.a.i.RemoteConfigLongPollService : Long polling failed, will retry in 2 seconds. appId: vx-tms-app, cluster: default, namespaces: application.properties, long polling url: null, reason: Get config services failed from http://apollo.meta/services/config?appId=vx-tms-app&ip=10.92.33.45 [Cause: Could not complete get operation [Cause: apollo.meta]]
- 2022-07-27 19:24:47.424 WARN 18980 --- [ main] c.c.f.a.i.AbstractConfigRepository : Sync config failed, will retry. Repository class com.ctrip.framework.apollo.internals.RemoteConfigRepository, reason: Get config services failed from http://apollo.meta/services/config?appId=vx-tms-app&ip=10.92.33.45 [Cause: Could not complete get operation [Cause: apollo.meta]]
- 2022-07-27 19:24:49.443 WARN 18980 --- [ngPollService-1] c.c.f.a.i.RemoteConfigLongPollService : Long polling failed, will retry in 4 seconds. appId: vx-tms-app, cluster: default, namespaces: application.properties+application, long polling url: null, reason: Get config services failed from http://apollo.meta/services/config?appId=vx-tms-app&ip=10.92.33.45 [Cause: Could not complete get operation [Cause: apollo.meta]]
本地和环境上分属不同的私服库,需要在pom代码中指定对应的仓库;具体的直接在私服中搜寻后,手动替换
- <repositories>
- <repository>
- <id>vxmaven</id>
- <name>vxmaven</name>
- <url>https://nexus3.vx56.com/repository/maven-releases/</url>
- </repository>
- <repository>
- <id>vx-local-maven</id>
- <name>vx-local-maven</name>
- <url>http://40.73.68.126:8080/repository/vx-hosted/</url>
- </repository>
- <repository>
- <id>vx-local-maven-proxy</id>
- <name>vx-local-maven</name>
- <url>http://40.73.68.126:8080/repository/vx-proxy/</url>
- </repository>
- </repositories>
- <pluginRepositories>
- <pluginRepository>
- <id>vxmaven</id>
- <name>vxmaven</name>
- <url>https://nexus3.vx56.com/repository/maven-releases/</url>
- </pluginRepository>
- <pluginRepository>
- <id>vx-local-maven</id>
- <name>vx-local-maven</name>
- <url>http://40.73.68.126:8080/repository/vx-hosted/</url>
- </pluginRepository>
- <pluginRepository>
- <id>vx-local-maven-proxy</id>
- <name>vx-local-maven-proxy</name>
- <url>http://40.73.68.126:8080/repository/vx-proxy/</url>
- </pluginRepository>
- </pluginRepositories>
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。