Open Source Configuration Center - Apollo
Apollo is a configuration management platform developed by Ctrip's framework department. It can centrally manage the configurations of different environments and clusters of applications. After configuration modification, it can be pushed to the application side in real time, and has standardized permissions, process governance and other characteristics. The server is developed based on Spring Boot and Spring Cloud. It can be run directly after packaging, and there is no need to install additional application containers such as Tomcat.
Check out code
apollo github
You can use idea to open it locally
Database Scripts
Run the following script to create ApolloConifgDB, ApolloPortalDB
Start configservice adminservice
Main class configuration
com.ctrip.framework.apollo.assembly.ApolloApplication
VM opinions
-Dapollo_profile=github -Dspring.datasource.url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8 -Dspring.datasource.username=root -Dspring.datasource.password=Program arguments-configservice --adminservice
After starting, open http://localhost:8080 and you can see that both apollo-configservice and apollo-adminservice have been started and registered with Eureka.
Start Apollo-Portal
Main class configuration
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=
If auth profile is enabled, the default user name is apollo and the password is admin
Applied on SIT, UAT, production environment machines
1. Add a directory /opt/data/ directory, and has read and write permissions;
2. Added new file: /opt/settings/server.properties and added configuration:
env=DEVsit: env=FATuat: env=UAT Production: env=PRO
Client Example
@Component Set component name @RefreshScope Specifies that configuration changes can be refreshed @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); }}Set up monitoring
@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()); }}Summarize
The above is the spring cloud Apollo apollo local development environment construction process introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!