In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Archaius configuration management API, including a series of configuration management API, provides dynamic typed properties, thread-safe configuration operations, polling framework, callback mechanism and other functions.
Overview
Archaius is one of the open source projects of Netflix Company, which is based on java configuration management class library, which is mainly used for dynamic acquisition of multi-configuration storage. The main function is the extension of the apache common configuration class library. It can be used as a dependent component of distributed configuration management in cloud platform development. At the same time, it has the following features:
Dynamically typed attribute
Efficient and thread-safe configuration operations
Callback mechanism when configuration changes
Polling framework
JMX, checking and invoking operation properties through Jconsole
Combined configuration
P_w_picpath.png
Applicable scenario
For traditional single applications, configuration files such as properties can solve the configuration problem, and at the same time, different environments can be distinguished through maven profile configuration. But in a micro-service ecology with hundreds of nodes, micro-services are developed in multiple languages, and the configuration files are in various formats. How to update the configuration files of each micro-service, and often need to restart the service, is an unbearable thing. Therefore, for the micro-service architecture, a general configuration center is essential.
The new interface is logically online, and the old interface is facing migration. After the development and testing is completed, it will be launched immediately. However, the R & D students of the interface call have some doubts about the stability and performance of the new interface. In order to avoid risk, they are required to switch back to the old interface urgently after being online. At this point, we need a manual switch. Therefore, for similar requirements, a general configuration center is essential.
The DynamicIntProperty class provided by Archaius can dynamically obtain the configuration when the configuration changes, and there is no need to restart the application. For the underlying configuration storage, it is recommended to use zookeeper for storage, and Archaius is used as the client class library.
The code case introduces relying on com.netflix.archaius archaius-core custom ConfigurationPropertiesConfigurationpublic class PropertiesConfiguration extends DynamicConfiguration {private static final Logger LOGGER = LoggerFactory.getLogger (PropertiesConfiguration.class); private static final int INITIAL_DELAY_MILLIS = 0; private static final int DELAY_MILLIS = 60 * 1000; private static final boolean IGNORE_DELETES_FROM_SOURCE = true; public PropertiesConfiguration (String confDir) {this (new String [] {confDir}) } public PropertiesConfiguration (final String...confDirs) {String [] propertiesPaths = Lists.newArrayList (Iterables.transform (Arrays.asList (confDirs), new Function () {@ Nullable @ Override public List apply (String confDir) {Assert.isTrue (new File (confDir). IsDirectory (), StringUtil.format ("path [{}] cannot find [.properties] file", confDirs) String [] propertiesPaths = getPaths (confDir); if (ArrayUtils.isNotEmpty (propertiesPaths)) {return Lists.newArrayList (propertiesPaths);} else {return Lists.newArrayList ();}) .toArray (new String [0]) If (ArrayUtils.isNotEmpty (propertiesPaths)) {super.startPolling (new URLConfigurationSource (propertiesPaths), new FixedDelayPollingScheduler (INITIAL_DELAY_MILLIS, DELAY_MILLIS, IGNORE_DELETES_FROM_SOURCE));} ConfigurationLog.successInit (PropertiesConfiguration.class, this.getProperties ());} private static String [] getPaths (String confDir) {try {URL configHome = new File (confDir). ToURI (). ToURL () List urls = new ArrayList (); for (String filename: FileUtil.scan (confDir, ".properties $")) {String url = configHome.toString () + filename; urls.add (url);} return urls.toArray (new String [urls.size ()]);} catch (MalformedURLException e) {throw Throwables.propagate (e) }} SystemConfigurationpublic class SystemConfiguration extends ConcurrentMapConfiguration {private static final Logger LOGGER = LoggerFactory.getLogger (SystemConfiguration.class); public SystemConfiguration () {super (); this.loadProperties (System.getProperties ()); ConfigurationLog.successInit (SystemConfiguration.class, this.getProperties ());}}
Similarly, you can use zookeeper client to encapsulate a zookeeper-based ConcurrentMapConfiguration
Initialize private static final ConcurrentCompositeConfiguration compositeConfig = new ConcurrentCompositeConfiguration (); public synchronized static void init () {Preconditions.checkState (! HadInit, StringUtil.format ("[{}] can only be loaded once!", ConfigAdapter.class.getSimpleName ()); Preconditions.checkState (compositeConfig.getConfigurations (). Size () > 1, StringUtil.format ("[{}] does not have any configuration loaded", ConfigAdapter.class.getSimpleName (); if (! ConfigurationManager.isConfigurationInstalled () {ConfigurationManager.install (compositeConfig); Preconditions.checkState (ConfigurationManager.isConfigurationInstalled (), StringUtil.format ("[{}] load failed!", ConfigAdapter.class.getSimpleName ());} Iterable configurationNames = Iterables.transform (compositeConfig.getConfigurations (), new Function () {@ Nullable @ Override public String apply (AbstractConfiguration input) {return input.getClass () .getSimpleName ()) }}); ConfigurationLog.successInit (ConfigAdapter.class, getAll ()); hadInit = true;} get the value public static DynamicBooleanProperty getDynamicBool (String key, boolean defaultValue) {return getFactory (). GetBooleanProperty (key, defaultValue);} private static DynamicPropertyFactory getFactory () {return DynamicPropertyFactory.getInstance ();} attention
Get the configuration at the time of the setting, and the configuration source will not be updated with the configuration updates in System#properties.
The update configuration method will not update the actual property file, only to update the memory data, and will fail after restart.
Micro services dynamically read configuration information from the configuration center, and the configuration center is synchronizing configuration from the configuration source, so there is a natural read and write security problem here. The good news is that Archaius has solved this problem, Archaius is thread safe, and read and write can be done concurrently.
Personal introduction:
Gao Guangchao: many years of experience in front-line Internet research and development and architecture design, good at designing and landing high-availability, high-performance Internet architecture.
This article is first published in Gao Guangchao's short book blog, please note!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.