RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
apollo如何搭建本地开发环境

这篇文章主要为大家展示了“apollo如何搭建本地开发环境”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“apollo如何搭建本地开发环境”这篇文章吧。

10余年的镇坪网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整镇坪建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联公司从事“镇坪网站设计”,“镇坪网站推广”以来,每个客户项目都认真落实执行。

开源配置中心 - Apollo

Apollo(阿波罗)是携程框架部门研发的配置管理平台,能够集中化管理应用不同环境、不同集群的配置,配置修改后能够实时推送到应用端,并且具备规范的权限、流程治理等特性。服务端基于Spring Boot和Spring Cloud开发,打包后可以直接运行,不需要额外安装Tomcat等应用容器。

检出代码

apollo github

可以fork下然后本地使用idea打开

数据库脚本

执行以下脚本创建ApolloConifgDB、ApolloPortalDB

  • apollo.scripts.sql.apolloconfigdb.sql

  • apollo.scripts.sql.apolloportaldb.sql

启动configservice adminservice

Main class配置

com.ctrip.framework.apollo.assembly.ApolloApplication

VM opions

-Dapollo_profile=github 
-Dspring.datasource.url=jdbc:MySQL://localhost:3306/ApolloConfigDB?characterEncoding=utf8 
-Dspring.datasource.username=root 
-Dspring.datasource.password=
Program arguments
--configservice --adminservice

启动完后,打开 http://localhost:8080可以看到apollo-configservice和apollo-adminservice都已经启动完成并注册到Eureka

启动Apollo-Portal

Main class配置

com.ctrip.framework.apollo.portal.PortalApplication
-Dapollo_profile=github,auth 
-Ddev_meta=http://localhost:8080/ 
-Dserver.port=8070 
-Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8 
-Dspring.datasource.username=root 
-Dspring.datasource.password=

如果启用了auth profile的话,默认的用户名是apollo,密码是admin

应用在SIT、UAT、生产环境机器上

1.新增目录/opt/data/目录,且有可读写权限;

2.新增文件:/opt/settings/server.properties 且加入配置:

env=DEV
sit: env=FAT
uat: env=UAT
生产:env=PRO

客户端例子

@Component 设置组件名称
@RefreshScope 指定配置改变可以刷新
@ConfigurationProperties(prefix = "redis.cache")
@Component("sampleRedisConfig")
@RefreshScope
public class SampleRedisConfig {
 private static final Logger logger = LoggerFactory.getLogger(SampleRedisConfig.class);
 private int expireSeconds;
 private String clusterNodes;
 private int commandTimeout;
 private Map someMap = Maps.newLinkedHashMap();
 private List someList = Lists.newLinkedList();
 @PostConstruct
 private void initialize() {
 logger.info(
  "SampleRedisConfig initialized - expireSeconds: {}, clusterNodes: {}, commandTimeout: {}, someMap: {}, someList: {}",
  expireSeconds, clusterNodes, commandTimeout, someMap, someList);
 }
 public void setExpireSeconds(int expireSeconds) {
 this.expireSeconds = expireSeconds;
 }
 public void setClusterNodes(String clusterNodes) {
 this.clusterNodes = clusterNodes;
 }
 public void setCommandTimeout(int commandTimeout) {
 this.commandTimeout = commandTimeout;
 }
 public Map getSomeMap() {
 return someMap;
 }
 public List getSomeList() {
 return someList;
 }
 @Override
 public String toString() {
 return String.format(
  "[SampleRedisConfig] expireSeconds: %d, clusterNodes: %s, commandTimeout: %d, someMap: %s, someList: %s",
   expireSeconds, clusterNodes, commandTimeout, someMap, someList);
 }
}

设置监听

@Component
public class SpringBootApolloRefreshConfig {
 private static final Logger logger = LoggerFactory.getLogger(SpringBootApolloRefreshConfig.class);
 @Autowired
 private ApolloRefreshConfig apolloRefreshConfig;
 @Autowired
 private SampleRedisConfig sampleRedisConfig;
 @Autowired
 private RefreshScope refreshScope;
 @ApolloConfigChangeListener
 public void onChange(ConfigChangeEvent changeEvent) {
 logger.info("before refresh {}", sampleRedisConfig.toString());
 refreshScope.refresh("sampleRedisConfig");
 logger.info("after refresh {}", sampleRedisConfig.toString());
 }
}

以上是“apollo如何搭建本地开发环境”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


分享名称:apollo如何搭建本地开发环境
文章链接:http://sczitong.cn/article/pdggpp.html