Project: Apollo (Provisioning / Automation & Configuration)
File: apollo-development-guide.md

This document describes how to compile and run Apollo locally using the IDE so that it can help you understand the inner workings of Apollo and also prepare you for custom development. Apollo local development requires the following components. Java: 1.8+ MySQL: 5.6.5+ (If you plan to use H2 in-memory database/H2 file database, then there is no need to prepare MySQL) IDE: No special requirements MySQL is required to create Apollo database and import the base data. Please refer to the following sections in for the specific steps. Please refer to for details. When we develop locally, we usually start `apollo-assembly` in the IDE. The following is an example of how to start `apollo-assembly` locally with Intellij Community 2016.2 version. `com.ctrip.framework.apollo.assembly.ApolloApplication` Note: If you want to start `apollo-portal`, `apollo-configservice` and `apollo-adminservice` independently, you can replace Main Class with `com.ctrip.framework.apollo.portal.PortalApplication` `com.ctrip.framework.apollo.configservice.ConfigServiceApplication` `com.ctrip.framework.apollo.adminservice.AdminServiceApplication` ``` -Dapollo_profile=github,auth ``` Note 1: apollo_profile is specified here as `github` and `auth`, where `github` is a profile required by Apollo for database configuration, and `auth` is added from 0.9.0 to support simple authentication using Spring Security provided by apollo. For more information you can refer to Note 2: If you plan to use a MySQL database, you need to add `spring.config-datasource.*` related configuration, the your-mysql-server:3306 needs to be replaced with the actual mysql server address and port, ApolloConfigDB and ApolloPortalDB needs to be replaced with the actual database name, apollo-username and apollo-password need to be replaced with the actual username and password ``` -Dspring.config-datasource.url=jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8 -Dspring.config-datasource.username=apollo-username -Dspring.config-datasource.password=apollo-password -Dspring.portal-datasource.url=jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8 -Dspring.portal-datasource.username=apollo-username -Dspring.portal-datasource.password=apollo-password ``` The initialization script for the MySQL database can be found in the scripts/sql/profiles/mysql-default directory of this project. Note 3: The default log output of the program is /opt/logs/100003171/apollo-assembly.log, if you need to modify the log file path, you can add the `logging.file.name` parameter, as follows. -Dlogging.file.name=/your-path/apollo-assembly.log Click Run or Debug for the new run configuration. After starting, open to see that both `apollo-configservice` and `apollo-adminservice` have been started and registered to Eureka. Note: In addition to confirming the service status in Eureka, you can also confirm the service health through the health check interface at. apollo-adminservice: apollo-configservice: If the service is healthy, the status.code in the return content should be `UP`. { "status": { "code": "UP", ... }, ... } After starting, open to see the Apollo Configuration Center interface. Note: If `auth` profile is enabled, the default username is apollo and password is admin For better development and debugging, we usually create a demo project for our own use. You can refer to to create your own demo project. There is a sample client project: , the following is an example of how to start it locally with Intellij. When creating a demo project in `2.2.5 Demo Application Access`, the system will ask to fill in a globally unique AppId, which we need to configure into the app.properties file of the `apollo-demo` project: `apollo-demo-java/api-demo/src/main/resources/

If our own demo project uses an AppId of 100004458, then the file content would be app.id=100004458 Note: AppId is the unique identity of the application, which is used by Apollo clients to get the application's own private Namespace configuration. For public Namespace configurations, you can get the configuration without the AppId, but then you lose the ability for the application to override the public Namespace configuration. More ways to configure AppId can be found in `com.apolloconfig.apollo.demo.api.SimpleApolloConfigDemo` -Dapollo.meta=http://localhost:8080 Note: Here the current environment's meta server address is `http://localhost:8080`, which is also the address of `apollo-configservice`. For more ways to configure Apollo Meta Server, please refer to Click Run or Debug on the newly created run configuration. After starting, ignore the previous debug message and you will see the following message. Apollo Config Demo. Please input key to get the value. Input quit to exit. > Enter the value you have configured on the Portal, such as `timeout` in our demo project, and you will see the following message. > timeout > [SimpleApolloConfigDemo] Loading key : timeout with value: 100 The default client log level is `DEBUG`, if you need to adjust it, you can modify the level in `apollo-demo/src/main/resources/log4j2.xml`. ```xml <logger name="com.ctrip.framework.apollo" additivity="false" level="trace"> <AppenderRef ref="Async" level="DEBUG"/> </logger> The project has a sample client project: `ApolloDemo`, here's an example of how to start it locally with VS 2010. When creating a Demo project in `2.2.5 Demo Application Access`, the system will ask to fill in a globally unique AppId, which we need to configure into the App.config file of the `ApolloDemo` project: `apollo.net\ApolloDemo\App.config`. If our own demo project uses an AppId of 100004458, then the contents of the file would be ```xml <add key="AppID" value="100004458"/> ``` Note: AppId is a unique identifier for the application, which Apollo clients use to get the application's own private Namespace configuration. For public Namespace configurations, the configuration can be obtained without the AppId, but the ability of the application to override the public Namespace configuration is lost. Apollo client will get the configuration from different servers for different environments, so we need to configure the server address (Apollo.{ENV}.Meta) in app.config or web.config. Suppose the DEV environment's configuration service (apollo-config service) address is 11.22.33.44, then we will do the following configuration. Just run `ApolloConfigDemo.cs`. After starting, ignore the previous debugging message and you will see the following prompt. Apollo Config Demo. Please input key to get the value. Input quit to exit. > Enter the value you configured on the Portal, such as `timeout` in our demo project, and you will see the following message. > timeout > Loading key: timeout with value: 100 Net client will output logs directly to the Console by default, so you can implement your own logging-related features. You can implement your own logging-related functions. See for details Apollo/Logging/Spi) Please refer to Please refer to Please refer to