### Manually Package Quick Start Installation Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start.md Steps to manually package the Apollo Quick Start installation if modifications are made to the code. This involves modifying POM files and executing a Maven command. ```sh mvn clean package -pl apollo-assembly -am -DskipTests=true ``` -------------------------------- ### Setup and Run Portal Auth Matrix (OIDC) Source: https://github.com/apolloconfig/apollo/blob/master/e2e/README.md Sets up OIDC authentication, starts the Apollo server with specific configurations, installs E2E dependencies, and runs the auth matrix tests in OIDC mode. ```bash cd /path/to/apollo ./e2e/portal-e2e/scripts/auth/setup-oidc.sh SPRING_PROFILES_ACTIVE=github,database-discovery,oidc \ SPRING_SQL_CONFIG_INIT_MODE=always \ SPRING_SQL_PORTAL_INIT_MODE=always \ SPRING_CONFIG_DATASOURCE_URL="jdbc:h2:mem:apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" \ SPRING_PORTAL_DATASOURCE_URL="jdbc:h2:mem:apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" \ SPRING_CONFIG_ADDITIONAL_LOCATION="file:/path/to/apollo/e2e/portal-e2e/config/application-oidc-e2e.yml" \ java -jar /path/to/apollo/apollo-assembly/target/apollo-assembly-*.jar cd e2e/portal-e2e npm ci npx playwright install --with-deps chromium PORTAL_AUTH_MODE=oidc BASE_URL=http://127.0.0.1:8070 npm run test:e2e:auth-matrix cd /path/to/apollo ./e2e/portal-e2e/scripts/auth/teardown-auth.sh ``` -------------------------------- ### Setup and Run Portal Auth Matrix (LDAP) Source: https://github.com/apolloconfig/apollo/blob/master/e2e/README.md Sets up LDAP authentication, starts the Apollo server with specific configurations, installs E2E dependencies, and runs the auth matrix tests in LDAP mode. ```bash cd /path/to/apollo ./e2e/portal-e2e/scripts/auth/setup-ldap.sh SPRING_PROFILES_ACTIVE=github,database-discovery,ldap \ SPRING_SQL_CONFIG_INIT_MODE=always \ SPRING_SQL_PORTAL_INIT_MODE=always \ SPRING_CONFIG_DATASOURCE_URL="jdbc:h2:mem:apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" \ SPRING_PORTAL_DATASOURCE_URL="jdbc:h2:mem:apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" \ SPRING_CONFIG_ADDITIONAL_LOCATION="file:/path/to/apollo/e2e/portal-e2e/config/application-ldap-e2e.yml" \ java -jar /path/to/apollo/apollo-assembly/target/apollo-assembly-*.jar cd e2e/portal-e2e npm ci npx playwright install --with-deps chromium PORTAL_AUTH_MODE=ldap BASE_URL=http://127.0.0.1:8070 npm run test:e2e:auth-matrix cd /path/to/apollo ./e2e/portal-e2e/scripts/auth/teardown-auth.sh ``` -------------------------------- ### Start Apollo Demo Client Source: https://github.com/apolloconfig/apollo/wiki/Quick-Start Run this command to start the demo client for interacting with Apollo configuration. ```sh ./demo.sh client ``` -------------------------------- ### Start Apollo Quick Start Source: https://github.com/apolloconfig/apollo/wiki/Quick-Start Execute this script to start the Apollo configuration center services locally. ```sh ./demo.sh start ``` -------------------------------- ### Example Properties File Content Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/java-sdk-user-guide.md This is an example of the content stored in the local configuration file, formatted as properties. ```properties request.timeout=2000 batch=2000 ``` -------------------------------- ### Start Apollo with Docker Compose Source: https://github.com/apolloconfig/apollo/wiki/Apollo-Quick-Start-Docker部署 Initiates the Apollo Quick Start environment using Docker Compose. This command downloads necessary images and starts the Apollo services. It may take some time on the first run. ```bash docker-compose up ``` -------------------------------- ### Install Apollo Portal with values.yaml Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/distributed-deployment-guide.md Install the apollo-portal using Helm with configurations defined in a values.yaml file. ```bash $ helm install apollo-portal -f values.yaml -n your-namespace apollo/apollo-portal ``` -------------------------------- ### Check Docker Installation Source: https://github.com/apolloconfig/apollo/wiki/Apollo-Quick-Start-Docker部署 Verify if Docker is installed correctly by checking its version. This is a prerequisite for using Docker. ```bash docker -v ``` -------------------------------- ### Example Properties Namespace Response Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/other-language-client-user-guide.md This is an example of the JSON response when fetching configuration from a namespace of type 'properties'. ```json { "portal.elastic.document.type": "biz", "portal.elastic.cluster.name": "hermes-es-fws" } ``` -------------------------------- ### Apollo Quick Start Service Startup Logs Source: https://github.com/apolloconfig/apollo/wiki/Apollo-Quick-Start-Docker部署 These logs indicate that the Apollo configuration service and portal have started successfully. You can access the portal via http://localhost:8070. ```log apollo-quick-start | ==== starting service ==== apollo-quick-start | Service logging file is ./service/apollo-service.log apollo-quick-start | Started [45] apollo-quick-start | Waiting for config service startup....... apollo-quick-start | Config service started. You may visit http://localhost:8080 for service status now! apollo-quick-start | Waiting for admin service startup...... apollo-quick-start | Admin service started apollo-quick-start | ==== starting portal ==== apollo-quick-start | Portal logging file is ./portal/apollo-portal.log apollo-quick-start | Started [254] apollo-quick-start | Waiting for portal startup....... apollo-quick-start | Portal started. You can visit http://localhost:8070 now! ``` -------------------------------- ### Install Apollo Services with Helm (using values.yaml) Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/distributed-deployment-guide.md Installs apollo-configservice and apollo-adminservice using a values.yaml file for configuration. This is the recommended approach for managing deployment configurations. ```bash $ helm install apollo-service-dev -f values.yaml -n your-namespace apollo/apollo-service ``` -------------------------------- ### Install Apollo Portal with Helm Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/distributed-deployment-guide.md Install the apollo-portal using Helm, specifying database connection details and environment meta server addresses. ```bash $ helm install apollo-portal \ --set portaldb.host=1.2.3.4 \ --set portaldb.userName=apollo \ --set portaldb.password=apollo \ --set portaldb.service.enabled=true \ --set config.envs="dev\,pro" \ --set config.metaServers.dev=http://apollo-service-dev-apollo-configservice:8080 \ --set config.metaServers.pro=http://apollo-service-pro-apollo-configservice:8080 \ --set replicaCount=1 \ -n your-namespace \ apollo/apollo-portal ``` -------------------------------- ### Local Configuration File Content Example Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/dotnet-sdk-user-guide.md In local development mode, configuration files are stored in JSON format. This example shows a JSON file with two key-value pairs for configuration settings. ```json { "request.timeout": "1000", "batch": "2000" } ``` -------------------------------- ### Apollo Config Demo Client Prompt Source: https://github.com/apolloconfig/apollo/wiki/Quick-Start This is the initial prompt when the Apollo Config Demo client starts. ```text Apollo Config Demo. Please input key to get the value. Input quit to exit. > ``` -------------------------------- ### Apollo Quick Start Startup Output Source: https://github.com/apolloconfig/apollo/wiki/Quick-Start This output indicates a successful startup of the Apollo configuration center services. ```text ==== starting service ==== Service logging file is ./service/apollo-service.log Started [10768] Waiting for config service startup....... Config service started. You may visit http://localhost:8080 for service status now! Waiting for admin service startup.... Admin service started ==== starting portal ==== Portal logging file is ./portal/apollo-portal.log Started [10846] Waiting for portal startup...... Portal started. You can visit http://localhost:8070 now! ``` -------------------------------- ### Install Apollo Release Skills Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/contribution/apollo-release-guide.md Use the `skill-installer` command to install the necessary release skills for the Apollo project. Ensure the source URL points to the apollo-skills repository. ```natural-language Use `skill-installer` to install `apollo-java-release`, `apollo-release`, and `apollo-helm-chart-release` from `https://github.com/apolloconfig/apollo-skills`. ``` -------------------------------- ### Subsequent Startup with H2 File Database Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start.md Start Apollo with an H2 file database after the initial setup. Remove initialization environment variables to prevent repeated initialization. ```bash export SPRING_PROFILES_ACTIVE="github,database-discovery,auth" # config db unset SPRING_SQL_CONFIG_INIT_MODE export SPRING_CONFIG_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" # portal db unset SPRING_SQL_PORTAL_INIT_MODE export SPRING_PORTAL_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" java -jar apollo-all-in-one.jar ``` -------------------------------- ### Public Namespace Configuration Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/design/apollo-core-concept-namespace.md Example of configuration items within a public namespace. ```properties k1 = v1 k2 = v2 ``` -------------------------------- ### Run Local E2E Tests Source: https://github.com/apolloconfig/apollo/blob/master/e2e/README.md Installs dependencies, installs Playwright browsers, and runs the E2E tests locally. Ensure the portal is running at the specified BASE_URL. ```bash cd e2e/portal-e2e npm ci npx playwright install --with-deps chromium BASE_URL=http://127.0.0.1:8070 npm run test:e2e ``` -------------------------------- ### Sample Java Version Output Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start.md Example output when checking the Java version, indicating a successful check. ```sh java version "17.0.14" Java(TM) SE Runtime Environment (build 17.0.14+7) Java HotSpot(TM) 64-Bit Server VM (build 17.0.14+7, mixed mode) ``` -------------------------------- ### Start Apollo with Docker Compose on ARM64 Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start-docker.md Use this command for ARM architecture machines (like Mac M1) to start Apollo services using the ARM64-specific Docker Compose file. ```bash docker-compose -f docker-compose-arm64.yml up ``` -------------------------------- ### Install Apollo Services with Helm (Directly) Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/distributed-deployment-guide.md Installs apollo-configservice and apollo-adminservice into a specified Kubernetes namespace using Helm. It requires database connection details and replica counts to be set via command-line arguments. Recommended for environments where a values.yaml file is not used. ```bash $ helm install apollo-service-dev \ --set configdb.host=1.2.3.4 \ --set configdb.userName=apollo \ --set configdb.password=apollo \ --set configdb.service.enabled=true \ --set configService.replicaCount=1 \ --set adminService.replicaCount=1 \ -n your-namespace \ apollo/apollo-service ``` -------------------------------- ### Example Non-Properties Namespace Response Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/other-language-client-user-guide.md This is an example of the JSON response when fetching configuration from a namespace that is not of type 'properties'. The content is typically a JSON string. ```json { "content": "{\"portal.elastic.document.type\":\"biz\",\"portal.elastic.cluster.name\":\"hermes-es-fws\"}" } ``` -------------------------------- ### SkyWalking Metrics Exporter Implementation Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/java-sdk-user-guide.md Extends AbstractApolloClientMetricsExporter to integrate with SkyWalking for metrics collection. This example demonstrates initializing the registry, registering counters and gauges, and handling metric updates. Note: This is an example and should be adapted for production use. ```java public class SkyWalkingMetricsExporter extends AbstractApolloClientMetricsExporter { private static final String SKYWALKING = "skywalking"; protected SkywalkingMeterRegistry registry; // When designing, users should consider if the data structure for storing metrics consumes too much memory. protected Map counterMap; private Map gaugeMap; private Map> gaugeValues; @Override public void doInit() { registry = new SkywalkingMeterRegistry(); counterMap = new ConcurrentHashMap<>(); gaugeValues = new ConcurrentHashMap<>(); gaugeMap = new ConcurrentHashMap<>(); } @Override public boolean isSupport(String form) { return SKYWALKING.equals(form); } @Override public void registerOrUpdateCounterSample(String name, Map tags, double incrValue) { String key = name + tags.toString(); Counter counter = counterMap.get(key); if (counter == null) { counter = createCounter(name, tags); counterMap.put(key, counter); } counter.increment(incrValue); } private Counter createCounter(String name, Map tags) { return Counter.builder(name) .tags(tags.entrySet().stream() .map(entry -> Tag.of(entry.getKey(), entry.getValue())) .collect(Collectors.toList())) .register(registry); } @Override public void registerOrUpdateGaugeSample(String name, Map tags, double value) { String key = name + tags.toString(); Gauge gauge = gaugeMap.get(key); if (gauge == null) { createGauge(name, tags, value); } else { gaugeValues.get(key).set(value); } } public void createGauge(String name, Map tags, double value) { String key = name + tags.toString(); AtomicReference valueHolder = gaugeValues.computeIfAbsent(key, k -> new AtomicReference<>(value)); gaugeMap.computeIfAbsent(key, k -> Gauge.builder(name, valueHolder::get) .tags(tags.entrySet().stream() .map(entry -> Tag.of(entry.getKey(), entry.getValue())) .collect(Collectors.toList())) .register(registry)); } @Override public String response() { // No need to implement in SkyWalking push mode return "This method does not need to be implemented in SkyWalking's push mode"; } } ``` -------------------------------- ### Start Apollo with H2 In-Memory Database Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start.md Use this command to start Apollo with an H2 in-memory database. Note that all data will be lost upon process restart. ```bash export SPRING_PROFILES_ACTIVE="github,database-discovery,auth" unset SPRING_SQL_CONFIG_INIT_MODE unset SPRING_SQL_PORTAL_INIT_MODE java -jar apollo-all-in-one.jar ``` -------------------------------- ### Check Java Version Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start.md Verify the installed Java version. Ensure it meets the minimum requirement of 17+. ```sh java -version ``` -------------------------------- ### Run CI E2E Tests Source: https://github.com/apolloconfig/apollo/blob/master/e2e/README.md Installs dependencies and runs the E2E tests in a CI environment. The BASE_URL should be set to the portal's address. ```bash cd e2e/portal-e2e BASE_URL=http://127.0.0.1:8070 npm run test:e2e:ci ``` -------------------------------- ### Get Configuration Items with Pagination Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/portal/apollo-open-api-platform.md Fetch configuration items for a namespace with support for pagination. Specify page number and size for controlling the results. ```json { "content": [ { "key": "timeout", "value": "3000", "comment": "timeout", "dataChangeCreatedBy": "mghio", "dataChangeLastModifiedBy": "mghio", "dataChangeCreatedTime": "2022-07-17T21:37:41.818+0800", "dataChangeLastModifiedTime": "2022-07-17T21:37:41.818+0800" }, { "key": "page.size", "value": "200", "comment": "page size", "dataChangeCreatedBy": "mghio", "dataChangeLastModifiedBy": "mghio", "dataChangeCreatedTime": "2022-07-17T21:37:41.818+0800", "dataChangeLastModifiedTime": "2022-07-17T21:37:41.818+0800" } ], "page": 0, "size": 50, "total": 2 } ``` -------------------------------- ### Apply Code Formatting Source: https://github.com/apolloconfig/apollo/blob/master/AGENTS.md Formats the code according to the project's style guide. This command must be run before submitting a Pull Request. ```bash ./mvnw spotless:apply ``` -------------------------------- ### Get Configuration Value Source: https://github.com/apolloconfig/apollo/wiki/Quick-Start Example of retrieving the 'timeout' configuration value from Apollo. ```text > timeout > [SimpleApolloConfigDemo] Loading key : timeout with value: 100 ``` -------------------------------- ### Get Updated Configuration Value Source: https://github.com/apolloconfig/apollo/wiki/Quick-Start Example of retrieving the 'timeout' configuration value after it has been updated. ```text > timeout > [SimpleApolloConfigDemo] Loading key : timeout with value: 200 ``` -------------------------------- ### Application C: Get Apollo Configuration Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/design/apollo-core-concept-namespace.md Retrieves configurations from the application's default namespace and attempts to get from 'NS-Private', falling back to default. Note: The example for 'NS-Public' is incomplete in the source. ```java //application Config appConfig = ConfigService.getAppConfig(); appConfig.getProperty("k1", null); // k1 = v12 appConfig.getProperty("k2", null); // k2 = null appConfig.getProperty("k3", null); // k3 = v33 // NS-Private, since there is no NS-Private Namespace so we get the default value Config privateConfig = ConfigService.getConfig("NS-Private"). privateConfig.getProperty("NS-Private"); privateConfig.getProperty("k1", "default value"); //NS-Public, the public type Namespace, which any project can get Config publicConfig = ConfigServi ``` -------------------------------- ### Get Meta Service URL Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/distributed-deployment-guide.md Retrieves the Meta Server URL for a deployed Apollo service release. This URL is required for apollo-portal installation. ```bash Get meta service url for current release by running these commands: echo http://apollo-service-dev-apollo-configservice:8080 ``` -------------------------------- ### Application C: Retrieving Configurations Source: https://github.com/apolloconfig/apollo/wiki/Apollo核心概念之“Namespace” Shows how Application C retrieves configurations from its private 'application' namespace and the public 'NS-Public' namespace. Demonstrates fetching keys and using default values when a namespace is not present. ```java //application Config appConfig = ConfigService.getAppConfig(); appConfig.getProperty("k1", null); // k1 = v12 appConfig.getProperty("k2", null); // k2 = null appConfig.getProperty("k3", null); // k3 = v33 //NS-Private,由于没有NS-Private Namespace 所以获取到default value Config privateConfig = ConfigService.getConfig("NS-Private"); privateConfig.getProperty("k1", "default value"); //NS-Public,公共类型的Namespace,任何项目都可以获取到 Config publicConfig = ConfigService.getConfig("NS-Public"); publicConfig.getProperty("k4", null); // k4 = v5 publicConfig.getProperty("k6", null); // k6 = v6 publicConfig.getProperty("k7", null); // k7 = v7 ``` -------------------------------- ### Health Check Response Example Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/contribution/apollo-development-guide.md Example of a healthy service response from the health check interface. The status.code should be 'UP'. ```json { "status": { "code": "UP", ... }, ... ``` -------------------------------- ### Configure startup.sh for LDAP Profile Source: https://github.com/apolloconfig/apollo/wiki/Portal-实现用户登录功能 Modify the scripts/startup.sh file to activate the LDAP profile. Set the 'spring.profiles.active' environment variable to 'github,ldap' to enable LDAP authentication. ```bash SERVICE_NAME=apollo-portal ## Adjust log dir if necessary LOG_DIR=/opt/logs/100003173 ## Adjust server port if necessary SERVER_PORT=8070 export JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=github,ldap" ``` -------------------------------- ### Prometheus Metrics Output Example Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/java-sdk-user-guide.md This is an example of the metrics output format that Prometheus will scrape from the exposed endpoint. It includes various Apollo client metrics. ```text # TYPE apollo_client_thread_pool_active_task_count gauge # HELP apollo_client_thread_pool_active_task_count apollo gauge metrics apollo_client_thread_pool_active_task_count{thread_pool_name="RemoteConfigRepository"} 0.0 apollo_client_thread_pool_active_task_count{thread_pool_name="AbstractApolloClientMetricsExporter"} 1.0 apollo_client_thread_pool_active_task_count{thread_pool_name="AbstractConfigFile"} 0.0 apollo_client_thread_pool_active_task_count{thread_pool_name="AbstractConfig"} 0.0 # TYPE apollo_client_namespace_timeout gauge # HELP apollo_client_namespace_timeout apollo gauge metrics apollo_client_namespace_timeout 0.0 # TYPE apollo_client_thread_pool_pool_size gauge # HELP apollo_client_thread_pool_pool_size apollo gauge metrics apollo_client_thread_pool_pool_size{thread_pool_name="RemoteConfigRepository"} 1.0 apollo_client_thread_pool_pool_size{thread_pool_name="AbstractApolloClientMetricsExporter"} 1.0 apollo_client_thread_pool_pool_size{thread_pool_name="AbstractConfigFile"} 0.0 apollo_client_thread_pool_pool_size{thread_pool_name="AbstractConfig"} 0.0 # TYPE apollo_client_thread_pool_queue_remaining_capacity gauge # HELP apollo_client_thread_pool_queue_remaining_capacity apollo gauge metrics apollo_client_thread_pool_queue_remaining_capacity{thread_pool_name="RemoteConfigRepository"} 2.147483647E9 apollo_client_thread_pool_queue_remaining_capacity{thread_pool_name="AbstractApolloClientMetricsExporter"} 2.147483647E9 apollo_client_thread_pool_queue_remaining_capacity{thread_pool_name="AbstractConfigFile"} 0.0 apollo_client_thread_pool_queue_remaining_capacity{thread_pool_name="AbstractConfig"} 0.0 # TYPE apollo_client_exception_num counter # HELP apollo_client_exception_num apollo counter metrics apollo_client_exception_num_total 1404.0 apollo_client_exception_num_created 1.729435502796E9 # TYPE apollo_client_thread_pool_largest_pool_size gauge # HELP apollo_client_thread_pool_largest_pool_size apollo gauge metrics apollo_client_thread_pool_largest_pool_size{thread_pool_name="RemoteConfigRepository"} 1.0 apollo_client_thread_pool_largest_pool_size{thread_pool_name="AbstractApolloClientMetricsExporter"} 1.0 apollo_client_thread_pool_largest_pool_size{thread_pool_name="AbstractConfigFile"} 0.0 apollo_client_thread_pool_largest_pool_size{thread_pool_name="AbstractConfig"} 0.0 # TYPE apollo_client_thread_pool_queue_size gauge # HELP apollo_client_thread_pool_queue_size apollo gauge metrics apollo_client_thread_pool_queue_size{thread_pool_name="RemoteConfigRepository"} 352.0 apollo_client_thread_pool_queue_size{thread_pool_name="AbstractApolloClientMetricsExporter"} 0.0 apollo_client_thread_pool_queue_size{thread_pool_name="AbstractConfigFile"} 0.0 apollo_client_thread_pool_queue_size{thread_pool_name="AbstractConfig"} 0.0 # TYPE apollo_client_namespace_usage counter # HELP apollo_client_namespace_usage apollo counter metrics apollo_client_namespace_usage_total{namespace="application"} 11.0 apollo_client_namespace_usage_created{namespace="application"} 1.729435502791E9 # TYPE apollo_client_thread_pool_core_pool_size gauge ``` -------------------------------- ### Application A: Retrieving Configurations Source: https://github.com/apolloconfig/apollo/wiki/Apollo核心概念之“Namespace” Demonstrates how Application A retrieves configurations from its private 'application' and 'NS-Private' namespaces, and its associated 'NS-Public' namespace. Shows specific key-value pairs obtained. ```java //application Config appConfig = ConfigService.getAppConfig(); appConfig.getProperty("k1", null); // k1 = v11 appConfig.getProperty("k2", null); // k2 = v21 //NS-Private Config privateConfig = ConfigService.getConfig("NS-Private"); privateConfig.getProperty("k1", null); // k1 = v3 privateConfig.getProperty("k3", null); // k3 = v4 //NS-Public,覆盖公共类型配置的情况,k4被覆盖 Config publicConfig = ConfigService.getConfig("NS-Public"); publicConfig.getProperty("k4", null); // k4 = v6 cover publicConfig.getProperty("k6", null); // k6 = v6 publicConfig.getProperty("k7", null); // k7 = v7 ``` -------------------------------- ### Application B: Retrieving Configurations Source: https://github.com/apolloconfig/apollo/wiki/Apollo核心概念之“Namespace” Illustrates how Application B retrieves configurations from its private 'application' namespace and the public 'NS-Public' namespace. Includes examples of retrieving keys and handling missing ones with default values. ```java //application Config appConfig = ConfigService.getAppConfig(); appConfig.getProperty("k1", null); // k1 = v12 appConfig.getProperty("k2", null); // k2 = null appConfig.getProperty("k3", null); // k3 = v32 //NS-Private,由于没有NS-Private Namespace 所以获取到default value Config privateConfig = ConfigService.getConfig("NS-Private"); privateConfig.getProperty("k1", "default value"); //NS-Public Config publicConfig = ConfigService.getConfig("NS-Public"); publicConfig.getProperty("k4", null); // k4 = v5 publicConfig.getProperty("k6", null); // k6 = v6 publicConfig.getProperty("k7", null); // k7 = v7 ``` -------------------------------- ### Client Config Service Discovery and Access Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/design/apollo-design.md Explains how a client discovers Config Service instances via Meta Server, performs load balancing, and accesses the service. ```mermaid sequenceDiagram Client ->> Meta Server: discovery Config Service's instances Meta Server -->> Client: Config Service's instances(Multiple IP+Port) loop until success Client ->> Client: load balance choose a Config Service instance Client ->> Config Service: request Config Service -->> Client: ack end ``` -------------------------------- ### Spring Integration Test Example Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/java-sdk-user-guide.md An example of a Spring integration test class using EmbeddedApollo to mock configurations. Ensure to use @DirtiesContext for proper context management. ```java @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = TestConfiguration.class) public class SpringIntegrationTest { // startup apollo's mockserver @ClassRule public static EmbeddedApollo embeddedApollo = new EmbeddedApollo(); @Test @DirtiesContext // This annotation is necessary because configuration injection can mess up the application context public void testPropertyInject(){ assertEquals("value1", testBean.key1); assertEquals("value2", testBean.key2); } @Test @DirtiesContext public void testListenerTriggeredByAdd() throws InterruptedException, ExecutionException, TimeoutException { String otherNamespace = "othernamespace"; embeddedApollo.addOrModifyPropery(otherNamespace,"someKey","someValue"); ConfigChangeEvent changeEvent = testBean.futureData.get(5000, TimeUnit.MILLISECONDS); assertEquals(otherNamespace, changeEvent.getNamespace()); assertEquals("someValue", changeEvent.getChange("someKey").getNewValue()); } @EnableApolloConfig("application") @Configuration static class TestConfiguration{ @Bean public TestBean testBean(){ return new TestBean(); } } static class TestBean{ @Value("${key1:default}") String key1; @Value("${key2:default}") String key2; SettableFuture futureData = SettableFuture.create(); @ApolloConfigChangeListener("othernamespace") private void onChange(ConfigChangeEvent changeEvent) { futureData.set(changeEvent); } } } ``` -------------------------------- ### First Startup with H2 File Database Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start.md Initialize Apollo with an H2 file database on the first startup. Ensure the specified paths have read/write permissions. Data is persisted across restarts. ```bash export SPRING_PROFILES_ACTIVE="github,database-discovery,auth" # config db export SPRING_SQL_CONFIG_INIT_MODE="always" export SPRING_CONFIG_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-config-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" # portal db export SPRING_SQL_PORTAL_INIT_MODE="always" export SPRING_PORTAL_DATASOURCE_URL="jdbc:h2:file:~/apollo/apollo-portal-db;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE" java -jar apollo-all-in-one.jar ``` -------------------------------- ### Build All Modules Source: https://github.com/apolloconfig/apollo/blob/master/AGENTS.md Builds all modules in the repository. Use this command to ensure all components are compiled. ```bash ./mvnw -DskipTests package ``` -------------------------------- ### Configure Meta Server via Java System Property Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/java-sdk-user-guide.md Set the 'apollo.meta' Java system property to specify the meta server URL. This can be done via the startup script using -Dapollo.meta=http://config-service-url or programmatically. ```bash java -Dapollo.meta=http://config-service-url -jar xxx.jar ``` ```java System.setProperty("apollo.meta", "http://config-service-url"); ``` -------------------------------- ### Get Prefix Path and Store in Local Storage Source: https://github.com/apolloconfig/apollo/blob/master/apollo-portal/src/main/resources/static/index.html Fetches the prefix path using an AJAX GET request and stores the response in the browser's local storage. This function is called immediately upon page load. ```javascript function getPrefixPath() { $.ajax({ method: 'get', async: false, url: 'prefix-path', success: function (res) { window.localStorage.setItem("prefixPath", res); } }) } getPrefixPath(); ``` -------------------------------- ### Configure Startup Script with Active Profiles Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/extension/portal-how-to-implement-user-login-function.md Modify the startup script to activate 'github' and 'oidc' profiles by setting the spring.profiles.active environment variable. ```bash SERVICE_NAME=apollo-portal ## Adjust log dir if necessary LOG_DIR=/opt/logs ## Adjust server port if necessary SERVER_PORT=8070 export JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=github,oidc" ``` -------------------------------- ### Apollo First Startup with MySQL Initialization Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start.md Use this command for the first startup of Apollo when using a MySQL database. It ensures that the database schemas are automatically initialized. Remember to replace placeholder values for your MySQL server address, database names, username, and password. ```bash export SPRING_PROFILES_ACTIVE="github,database-discovery,auth" # config db export SPRING_SQL_CONFIG_INIT_MODE="always" export SPRING_CONFIG_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloConfigDB?useUnicode=true&characterEncoding=UTF8" export SPRING_CONFIG_DATASOURCE_USERNAME="apollo-username" export SPRING_CONFIG_DATASOURCE_PASSWORD="apollo-password" # portal db export SPRING_SQL_PORTAL_INIT_MODE="always" export SPRING_PORTAL_DATASOURCE_URL="jdbc:mysql://your-mysql-server:3306/ApolloPortalDB?useUnicode=true&characterEncoding=UTF8" export SPRING_PORTAL_DATASOURCE_USERNAME="apollo-username" export SPRING_PORTAL_DATASOURCE_PASSWORD="apollo-password" java -jar apollo-all-in-one.jar ``` -------------------------------- ### Application B: Get Apollo Configuration Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/design/apollo-core-concept-namespace.md Retrieves configurations from the application's default namespace, attempts to get from 'NS-Private' (which may not exist, falling back to default), and retrieves from 'NS-Public'. Shows how values differ from Application A. ```java //application Config appConfig = ConfigService.getAppConfig(); appConfig.getProperty("k1", null); // k1 = v12 appConfig.getProperty("k2", null); // k2 = null appConfig.getProperty("k3", null); // k3 = v32 // NS-Private, since there is no NS-Private Namespace so we get the default value Config privateConfig = ConfigService.getConfig("NS-Private"). privateConfig.getProperty("NS-Private"); privateConfig.getProperty("k1", "default value"); //NS-Public Config publicConfig = ConfigService.getConfig("NS-Public"); publicConfig.getProperty("k4", null); // k4 = v5 publicConfig.getProperty("k6", null); // k6 = v6 publicConfig.getProperty("k7", null); // k7 = v7 ``` -------------------------------- ### Execute Build and Packaging Source: https://github.com/apolloconfig/apollo/wiki/分布式部署指南 Run the build.sh script after configuring database and meta service information. This script packages apollo-configservice, apollo-adminservice, and apollo-portal sequentially. ```sh ./build.sh ``` -------------------------------- ### Getting the cluster information Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/portal/apollo-open-api-platform.md Retrieves details for a specific cluster within an application and environment. ```APIDOC ## GET /openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName} ### Description Retrieves details for a specific cluster within an application and environment. ### Method GET ### Endpoint `http://{portal_address}/openapi/v1/envs/{env}/apps/{appId}/clusters/{clusterName}` ### Parameters #### Path Parameters - **env** (string) - Required - Managed configuration environment - **appId** (string) - Required - The managed configuration AppId - **clusterName** (string) - Required - The name of the managed configuration cluster ### Response #### Success Response (200) - **name** (string) - The name of the cluster - **appId** (string) - The AppId to which the cluster belongs - **dataChangeCreatedBy** (string) - User who created the data - **dataChangeLastModifiedBy** (string) - User who last modified the data - **dataChangeCreatedTime** (string) - Timestamp of data creation - **dataChangeLastModifiedTime** (string) - Timestamp of last data modification ``` -------------------------------- ### Apollo Assembly VM Options Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/contribution/apollo-development-guide.md Configure VM options for Apollo Assembly. Use 'github' profile for database configuration and 'auth' for simple authentication. ```bash -Dapollo_profile=github,auth ``` -------------------------------- ### AbstractApolloClientMetricsExporter Initialization Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/java-sdk-user-guide.md Illustrates how the doInit method is called within the init method of AbstractApolloClientMetricsExporter. This shows the lifecycle of the exporter's initialization process. ```java @Override public void init(List collectors, long collectPeriod) { // code doInit(); // code } ``` -------------------------------- ### Migrating Spring Boot Properties to Apollo Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/java-sdk-user-guide.md Example of Spring Boot configuration properties that can be migrated to Apollo. ```properties spring.application.name=reservation-service server.port = 8080 logging.level = ERROR eureka.client.service-url.defaultZone = http://127.0.0.1:8761/eureka/ eureka.client.healthcheck.enabled=true eureka.client.register-with-eureka = true eureka.client.fetch-registry = true eureka.client.eureka-service-url-poll-interval-seconds = 60 eureka.instance.prefer-ip-address = true ``` -------------------------------- ### Check MySQL Version Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start.md Verify the installed MySQL version. Apollo requires at least version 5.6.5+. ```sql SHOW VARIABLES WHERE Variable_name = 'version'; ``` -------------------------------- ### Spring Annotation Support with Apollo Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/client/java-sdk-user-guide.md Demonstrates the usage of Apollo's Spring annotations for injecting configuration objects and listeners. ```java public class TestApolloAnnotationBean { @ApolloConfig private Config config; //inject config for namespace application @ApolloConfig("application") private Config anotherConfig; //inject config for namespace application @ApolloConfig("FX.apollo") private Config yetAnotherConfig; //inject config for namespace FX.apollo @ApolloConfig("application.yml") private Config ymlConfig; //inject config for namespace application.yml /** * ApolloJsonValue annotated on fields example, the default value is specified as empty list - [] *
* jsonBeanProperty=[{"someString":"hello","someInt":100},{"someString":"world!","someInt":200}] */ @ApolloJsonValue("${jsonBeanProperty:[]}") private List anotherJsonBeans; @Value("${batch:100}") private int batch; //config change listener for namespace application @ApolloConfigChangeListener private void someOnChange(ConfigChangeEvent changeEvent) { //update injected value of batch if it is changed in Apollo if (changeEvent.isChanged("batch")) { batch = config.getIntProperty("batch", 100); } } //config change listener for namespace application @ApolloConfigChangeListener("application") private void anotherOnChange(ConfigChangeEvent changeEvent) { //do something } //config change listener for namespaces application, FX.apollo and application.yml @ApolloConfigChangeListener({"application", "FX.apollo", "application.yml"}) private void yetAnotherOnChange(ConfigChangeEvent changeEvent) { //do something } //example of getting config from Apollo directly //this will always return the latest value of timeout public int getTimeout() { return config.getIntProperty("timeout", 200); } //example of getting config from injected value //the program needs to update the injected value when batch is changed in Apollo using @ApolloConfigChangeListener shown above public int getBatch() { return this.batch; } private static class JsonBean{ private String someString; private int someInt; } } ``` -------------------------------- ### Get App information Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/portal/apollo-open-api-platform.md Retrieves information about one or more applications. If no appIds are provided, it returns all application information. ```APIDOC ## GET /openapi/v1/apps ### Description Retrieves information about one or more applications. If no appIds are provided, it returns all application information. ### Method GET ### Endpoint `http://{portal_address}/openapi/v1/apps` ### Parameters #### Query Parameters - **appIds** (string) - Optional - List of appIds, separated by commas, or return all app information if empty ### Response #### Success Response (200) - **name** (string) - The name of the application - **appId** (string) - The unique identifier for the application - **orgId** (string) - The organization ID - **orgName** (string) - The organization name - **ownerName** (string) - The owner's name - **ownerEmail** (string) - The owner's email - **dataChangeCreatedBy** (string) - User who created the data - **dataChangeLastModifiedBy** (string) - User who last modified the data - **dataChangeCreatedTime** (string) - Timestamp of data creation - **dataChangeLastModifiedTime** (string) - Timestamp of last data modification ``` -------------------------------- ### Directory Structure for Docker Compose Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/deployment/quick-start-docker.md This illustrates the expected directory structure after downloading the Docker Compose configuration files and SQL scripts. ```text - docker-quick-start - docker-compose.yml - sql - apolloconfigdb.sql - apolloportaldb.sql ``` -------------------------------- ### Get Non-Application Namespace Configuration Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/design/apollo-core-concept-namespace.md Use this method to retrieve configuration for a custom namespace by providing its name. ```java Config config = ConfigService.getConfig(namespaceName); ``` -------------------------------- ### Configure Meta Service via System Environment Variable Source: https://github.com/apolloconfig/apollo/wiki/分布式部署指南 Shows how to set the meta service address for a specific environment using an operating system's System Environment variable. The key must be in uppercase with an underscore separator (e.g., DEV_META). ```sh DEV_META=http://config-service-url ``` -------------------------------- ### Get App's environment, cluster information Source: https://github.com/apolloconfig/apollo/blob/master/docs/en/portal/apollo-open-api-platform.md Retrieves a list of environments and their associated clusters for a given application. ```APIDOC ## GET /openapi/v1/apps/{appId}/envclusters ### Description Retrieves a list of environments and their associated clusters for a given application. ### Method GET ### Endpoint `http://{portal_address}/openapi/v1/apps/{appId}/envclusters` ### Parameters #### Path Parameters - **appId** (string) - Required - The managed configuration AppId ### Response #### Success Response (200) - **env** (string) - The managed configuration environment - **clusters** (array) - A list of cluster names for the environment ```