Apollo and the basic concepts of integrated combat

The basic concept of using the scene # ** ** is a distributed configuration center. Suitable for micro services; ** ** 1. Centralized management of the core functions of different environments, configure different clusters; 2. configuration changes can be pushed to real-time application side; 3. have standard permissions, flow control characteristics; development technology ** ** * the service uses springboot, springcloud development, the package can be run directly, without having to install additional tomcat; * java client does not rely on any framework, Spring, springBoot clients also have additional support * .net client does not rely on any conceptual framework ** ** | abbreviations | stands | Description | || - || | FAT || functional test environment | | UAT || integrated test environment | | PRO || production environment | | DEV || development environment | ** ** 1. detailed features unified management of different environments, different clusters, different namespace configuration; 1. the same code can be deployed in different clusters can have different configurations, such as address 1. zk easy by namespace support different applications to share the same copy of configuration, while still allowing applications to cover shared configuration; 1. configuration changes take effect immediately (in the background the user to modify the configuration after release, the client can receive in 1s The new configuration and notifies applications) 1. release concept (all configuration has released version concept, can easily support rollback configuration) 1. gray-release (posted after the configuration, the detachment of part of the application instance entry into force, etc. after a period of observation pushed in all the applications) 1. rights management, post audit, operational audit 1. the client configuration information monitoring (easily see which is used to configure instances) 1. support multiple languages, java and .net by http interface is also supported; 1. to provide an open platform api to modify and distribute to other operating systems; deployment 1. use a simple background # [background interface operation] (https://github.com/ctripcorp/apollo/wiki / Apollo% E4% BD% BF% E7% 94% A8% E6% 8C% 87% E5% 8D% 97) [client access document] (https: // github. com / ctripcorp / apollo / wiki / Java% E5% AE% A2% E6% 88% B7% E7% AB% AF% E4% BD% BF% E7% 94% A8% E6% 8C% 87% E5% 8D% 97) ## 1. background Action 1. create a project administrator assign permissions allocation (project management, create a cluster, create a namespace) to edit and publish 1. assign permissions configuration 1. Add configuration items, modify configuration item 1. publish configuration, the replacement configuration; 1 read configuration is used in the end application; in particular, see the document access client; ** ** operation common components> common components: available to other tissues used by the application client code, such as cat client; part of the essence is applied; * difference *: normally, configured to use common components are maintained by the original development team, but the actual application at runtime environment is different, so we also allow application in the actual time used to cover part of the public assembly configuration; you need to create your own own unique namespace; operation of public assembly 1. create a project 1. assign project administrator privileges 1. create a namespace 1. add configuration items, publish; 1. public 1. read the configuration application associated well And covering the common component assembly CI ** ** 1. Add cluster configuration separate clusters, cluster default; for appId plurality 1. 1. use the same configuration with common components, associated namespace, a common configuration is written or configured to cover the common ** ** gray publish operate 1. 1. create a gray gray gray rule configuration 1. add, modify 1. 1. gray publish the full amount released, giving up ## gray 1. publish the client history the> requires: jdk1.7 +, guava15.0 +> ** client configuration parameters ** 1. app.id (systemProperty> System Environment> springboot application.properties> META-INF / app.properties) id corresponding item 1. apollo.meta access address (SystemProperty> com.ctrip.framework.apollo apollo-client 1.1.0 `` `** ** contrast access | access | Features | | - | - | | api | flexible, full-featured | | spring | placeholder way | | springboot | @ConfigurationProperties | ### API access> Get application namespace configuration `` `java config config = ConfigService.getAppConfig (); // config instance is singleton for each namespace and is never null String value = config.getProperty (someKey, someDefaultValue);` ``> Get public namespace ` `` java String somePublicNamespace = "CAT"; config config = ConfigService.getConfig (somePublicNamespace); // config instance is singleton for each namespace and is never null String value = config.getProperty (someKey, someDefaultValue); `` `non-acquisition namespace configuration properties format `` `java config config = ConfigService.getConfig (" application.yml "); String value = config.getProperty (someKey, someDefaultValue);` ``> xml format file obtaining `` `java String someNamespace = "test";ConfigFile configFile = ConfigService.getConfigFile("test", ConfigFileFormat.XML); String content = configFile.getContent(); ``` > 事件监听 ```java Config config = ConfigService.getAppConfig(); //config instance is singleton for each namespace and is never null config.addChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { System.out.println("Changes for namespace " + changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xmlgetConfigFile("test", ConfigFileFormat.XML); String content = configFile.getContent(); ``` > 事件监听 ```java Config config = ConfigService.getAppConfig(); //config instance is singleton for each namespace and is never null config.addChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { System.out.println("Changes for namespace " + changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xmlgetConfigFile("test", ConfigFileFormat.XML); String content = configFile.getContent(); ``` > 事件监听 ```java Config config = ConfigService.getAppConfig(); //config instance is singleton for each namespace and is never null config.addChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { System.out.println("Changes for namespace " + changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xmlgetContent(); ``` > 事件监听 ```java Config config = ConfigService.getAppConfig(); //config instance is singleton for each namespace and is never null config.addChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { System.out.println("Changes for namespace " + changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xmlgetContent(); ``` > 事件监听 ```java Config config = ConfigService.getAppConfig(); //config instance is singleton for each namespace and is never null config.addChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { System.out.println("Changes for namespace " + changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xmladdChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { System.out.println("Changes for namespace " + changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xmladdChangeListener(new ConfigChangeListener() { @Override public void onChange(ConfigChangeEvent changeEvent) { System.out.println("Changes for namespace " + changeEvent.getNamespace()); for (String key : changeEvent.changedKeys()) { ConfigChange change = changeEvent.getChange(key); System.out.println(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xmlprintln(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xmlprintln(String.format("Found change - key: %s, oldValue: %s, newValue: %s, changeType: %s", change.getPropertyName(), change.getOldValue(), change.getNewValue(), change.getChangeType())); } } }); ``` ### spring方式接入 > 基于xml ```xml `> Based javaconfig` `` java // This is the most complex configurations, and indicating Apollo injection FX.apollo Spring application.yml namespace configuration to the environment, and the order in front of application @Configuration @EnableApolloConfig (order = 2) public class SomeAppConfig {@Bean public TestJavaConfigBean javaConfigBean () {return new TestJavaConfigBean ();}} @Configuration @EnableApolloConfig (value = { "FX.apollo", "application.yml"}, order = 1) public class AnotherAppConfig {} `` `### springboot access mode> disposed directly` `` text # properties corresponding to the application to load a configuration file application namespace apollo.bootstrap.enabled = true # apollo.bootstrap.namespaces load configuration of other namespace = application, FX.apollo, application.yml # loading Apollo apollo.bootstrap.eagerLoad.enabled = true `` `### further instructions before the system starts logging>Some of the new public comment spring annotation * @ApolloConfig used to automatically inject Config object * @ApolloConfigChangeListener used to automatically register ConfigChangeListener * @ApolloJsonValue json string used to configure automatically injected into the migration target ### configured migration configuration 1. apollo create the corresponding item; 1. create a good META-INF / app.properties in the application, and configured; 1. the original configuration file, convert properties, attached to the apollo background; 1. delete the local configuration ; ### /opt/settins/server.properties local development 1. modify settings env = local 1. preparation local profile location: Mac / Linux: / opt / data / {appId} / config-cache Windows: C: \ opt \ data \ {appId} \ config-cache 1. modify the local configuration will not detect changes in real time, the need to restart the application; # 1. existing project transformation step of removing dependency disconf to find the corresponding xml, removing bean stated configuration ; 2. search for the corresponding @Disf, if the class directly remove, if in the field or method, is replaced @Value annotations; 3. increase in the xml configuration apollo; `` `xmlModifying the local configuration does not detect changes in real time, the need to restart the application; # 1. existing project transformation step of removing dependency disconf to find the corresponding xml, remove the stated configuration bean; 2. search for the corresponding @Disf, if the class , directly remove, if in the field or method, is replaced @Value annotations; 3. increase in the xml configuration apollo; `` `xmlModifying the local configuration does not detect changes in real time, the need to restart the application; # 1. existing project transformation step of removing dependency disconf to find the corresponding xml, remove the stated configuration bean; 2. search for the corresponding @Disf, if the class , directly remove, if in the field or method, is replaced @Value annotations; 3. increase in the xml configuration apollo; `` `xml `1. Because of the presence of dependent classes path before mysql.properties; apollo the files is not generated so much; apollo 1. In the background, the background from disconf configuration item has put under application.properties; 1 . New private namespace log4j2.xml, the logging configuration copy, put inside release; 1. if the same configuration with the public key, needs to be rewritten, the associated public namespace rewriting; 1. start program, compile solve error;

Guess you like

Origin www.cnblogs.com/snidget/p/11359575.html