spring cloud 阿波羅 apollo 本地開發環境搭建過程,cloudapollo

來源:互聯網
上載者:User

spring cloud 阿波羅 apollo 本地開發環境搭建過程,cloudapollo

開源配置中心 - 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=DEVsit: env=FATuat: env=UAT生產:env=PRO

用戶端例子

@Component 設定組件名稱@RefreshScope 指定配置改變可以重新整理@ConfigurationProperties(prefix = "redis.cache")@Component("sampleRedisConfig")@RefreshScopepublic 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); }}

設定監聽

@Componentpublic 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()); }}

總結

以上所述是小編給大家介紹的spring cloud 阿波羅 apollo 本地開發環境搭建過程,希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對幫客之家網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.