Spring cloud apollo Local Development Environment setup process, cloudapollo

Source: Internet
Author: User

Spring cloud apollo Local Development Environment setup process, cloudapollo

Open-source configuration center-Apollo

Apollo is a configuration management platform developed by the Ctrip framework department. It centrally manages the configurations of different environments and clusters of applications. After configuration modification, it can be pushed to the application end in real time, it also has standardized permissions, process governance, and other features. The server is developed based on Spring Boot and Spring Cloud. After packaging, the server can run directly without the need to install Tomcat and other application containers.

Check out code

Apollo github

You can run the fork command and use idea locally.

Database script

Execute the following script to create the following commands:

  • Apollo. scripts. SQL. apollo configdb. SQL
  • Apollo. scripts. SQL. apolloportaldb. SQL

Start configservice adminservice

Main class configuration

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

After starting, open http: // localhost: 8080 and you can see that both the apollo-configservice and the apollo-adminservice have been started and registered to 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.

Applications on SIT, UAT, and production machines

1. added the/opt/data/directory with the read/write permission;

2. added the file:/opt/settings/server. properties and added the Configuration:

Env = DEVsit: env = FATuat: env = UAT production: env = PRO

Client example

@ Component set the Component name @ RefreshScope to specify the configuration change. You can refresh @ 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. newjavashashmap (); private List <String> someList = Lists. newshortlist (); @ PostConstruct private void initialize () {logger.info ("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 listeners

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

Summary

The above section describes how to set up the spring cloud apollo local development environment. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.