spring cloud 阿波羅 apollo 本地開發(fā)環(huán)境搭建過程
開源配置中心 - Apollo
Apollo(阿波羅)是攜程框架部門研發(fā)的配置管理平臺,能夠集中化管理應(yīng)用不同環(huán)境、不同集群的配置,配置修改后能夠?qū)崟r推送到應(yīng)用端,并且具備規(guī)范的權(quán)限、流程治理等特性。服務(wù)端基于Spring Boot和Spring Cloud開發(fā),打包后可以直接運行,不需要額外安裝Tomcat等應(yīng)用容器。
檢出代碼
可以fork下然后本地使用idea打開
數(shù)據(jù)庫腳本
執(zhí)行以下腳本創(chuàng)建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都已經(jīng)啟動完成并注冊到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的話,默認(rèn)的用戶名是apollo,密碼是admin
應(yīng)用在SIT、UAT、生產(chǎn)環(huán)境機器上
1.新增目錄/opt/data/目錄,且有可讀寫權(quán)限;
2.新增文件:/opt/settings/server.properties 且加入配置:
env=DEV sit: env=FAT uat: env=UAT 生產(chǎn):env=PRO
客戶端例子
@Component 設(shè)置組件名稱 @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<String, String> someMap = Maps.newLinkedHashMap(); private List<String> 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<String, String> getSomeMap() { return someMap; } public List<String> 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); } }
設(shè)置監(jiān)聽
@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()); } }
總結(jié)
以上所述是小編給大家介紹的spring cloud 阿波羅 apollo 本地開發(fā)環(huán)境搭建過程,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
java接收文件流+response.body()調(diào)用兩次問題(分別接收文件和對象)
這篇文章主要介紹了java接收文件流+response.body()調(diào)用兩次問題(分別接收文件和對象),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06