In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the hystrix configuration of Apollo and Archaius have any different related knowledge, the content is detailed and easy to understand, simple and fast operation, with a certain reference value, I believe you will gain after reading this hystrix configuration of Apollo and Archaius what different articles, let's take a look at it.
ARCHAIUS warning Log 2020-12-10 11 19c.n.c.sources.URLConfigurationSource main c.n.c.sources.URLConfigurationSource: No URLs will be polled as dynamic configuration sources.2020-12-10 11 main warning Log 12835-[main] c.n.c.sources.URLConfigurationSource: To enable URLs as dynamic configuration sources Define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.2020-12-10 11 main 19V 41.772 WARN 12835-[main] c.n.c.sources.URLConfigurationSource: No URLs will be polled as dynamic configuration sources.2020-12-10 11V 19V 41.772 INFO 12835-[main] c.n.c.sources.URLConfigurationSource: To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath. The problems we have
In a system optimization refactoring, the blogger slimmed down the entire project to 360, removing all unused dependencies. This includes the archaius-core dependency of the spring-cloud-starter-openfeign module. Because we have used the apollo configuration center, archaius is redundant in this project and prints annoying warning logs. So it is ruled out directly, such as:
Implementation ('org.springframework.cloud:spring-cloud-starter-openfeign') {exclude (module: "archaius-core")}
To this end, a special understanding of the origin of the archaius, and for the fuse of feign Fallback capabilities were tested, everything is running normally. A week after the launch, the problem was exposed, and colleagues reported that the configuration of hystrix did not seem to work. The phenomenon is that the hystrix thread originally set does not time out, but a lot of execution times out in one second. Our key configuration is as follows (this is not a good configuration demonstration, and more fine-grained control will be adjusted later):
# prohibit execution of timeout hystrix.command.default.execution.timeout.enabled = false
The intuitive feeling is that this configuration does not work, thinking that archaius-core has been removed, so the dependency is restored immediately, repackaged and launched, and the problem is solved. This is it? In order to thoroughly understand the configuration loading process of Hystrix, we have a comprehensive understanding of feign integration with hystrix.
The loading process of HYSTRIX in FEIGN
Under the encapsulation of spring-cloud-starter-openfeign, it is very easy to use, but the internal loading process is very complex. Therefore, bloggers do not intend to spread out this piece of content in an all-round way, but will speak independently when they have the opportunity. Here, based on the problem that the disabled execution timeout does not take effect, the blogger summarizes several key points in the loading process:
Bridge Feign-Hystrix for Feign and Hystrix
This project is a bridge between feign and hystrix, which integrates the api capabilities of the two frameworks. The following is a brief description of the role of the key classes in the loading process:
SetterFactory: the interface that carries all the configurations for constructing HystrixCommand instances. There is a default implementation of Default, which will be used below. It is a breakthrough for custom configuration implementation.
HystrixInvocationHandler: this is an implementation of the JDK proxy interface class, which is used to proxy the final execution of the Feign. The HystrixCommand class is constructed and executed in this instance. The constructor used is brought into the constructor of the parameter setter, and the integrator implements SetterFactory to construct the Setter. When we type the endpoint into this class when debugging the program, we can see how the configuration is loaded.
SPRING BOOT automatically loads HYSTRIX@Configuration@ConditionalOnClass ({HystrixCommand.class, HystrixFeign.class}) protected static class HystrixFeignConfiguration {@ Bean @ Scope ("prototype") @ ConditionalOnMissingBean @ ConditionalOnProperty (name = "feign.hystrix.enabled") public Feign.Builder feignHystrixBuilder () {return HystrixFeign.builder ();}}
This is the general entry for loading Hystrix under the feign framework. In the default builder Builder, there is a default implementation of SetterFactory, which is responsible for passing parameters to Hystrix for initializing HystrixCommand. You can see that the @ ConditionalOnMissingBean condition constraint is added to the instantiation of Bean. Since we can customize the constructor that implements Hystrix and override the implementation here, in the custom constructor, we can inject any configuration through custom implementation SetterFactory. This is one of the ways to implement custom loading of Hystrix configuration, but it is not recommended. There is no need to destroy the existing structure of spirng, and the code will be lengthy (the following {...} omitted more than 100 lines of configuration processing code to be compatible with Hystrix's existing configuration definition), as shown below:
Dynamic background configuration of HYSTRIX
Configuration is the core of hystrix, and the selection and implementation of various policies need to be driven by configuration. Therefore, although not too many configuration settings are required at the application level, the necessary configuration hystrix will be filled with a default value. For example, hystrix defaults to 1s of timeout settings. The configuration in Hystrix has three levels of load priority, such as:
Loading Setter:Setter first is passed to the Hystrix constructor by the user, so it has the highest priority
Second, load the dynamic configuration source: if the necessary configuration is not found in Setter, get it from the dynamic configuration source
Finally, load the default configuration: if the configuration is not found in the dynamic configuration source, the default configuration is used.
There is a dynamic configuration source and a SystemProperties-based configuration to implement HystrixDynamicPropertiesSystemProperties. When HystrixCommand is instantiated, if the user does not give a specific configuration, Hystrix will look for the configuration in SystemProperties every time. In other words, we can inject any Hystrix configuration parameter through the-D parameter, and it will take effect. With this feature, you can easily combine apollo to achieve the dynamic effect of hystrix configuration, and all configurations are compatible with the original configuration of Hystrix.
APOLLO configuration driver HYSTRIX
The key to achieving this function is. When the system is initialized, the configuration related to the hystrix.command prefix is obtained from apollo and injected into SystemProperties. When you update the configuration, you can update the configuration in SystemProperties at the same time. It is very simple to use the code:
/ * * @ author kl (http://kailing.pub) * @ since 2020-12-10 * / @ Slf4j@Configuration@AutoConfigureBefore (value = {FeignClientsConfiguration.class, FeignAutoConfiguration.class}) public class HystrixConfiguration {public static final String DYNAMIC_TAG = "dynamic."; public static final String DYNAMIC_PREFIX = DYNAMIC_TAG + "hystrix.command."; public static final String PREFIX = "hystrix.command."; @ ApolloConfig private Config config @ PostConstruct public void initHystrix () {this.config.addChangeListener (event-> this.loadHystrixConfig (event.changedKeys ()), null, Sets.newHashSet (DYNAMIC_PREFIX)); this.loadHystrixConfig (config.getPropertyNames ()) } private void loadHystrixConfig (Setconfigkyes) {configkyes.forEach (key-> {if (StringUtils.containsIgnoreCase (key, PREFIX)) {String value = config.getProperty (key, null); String realKey = key.replaceAll (DYNAMIC_TAG, "). Trim (); System.setProperty (realKey, value) Log.info ("Hystrix config: {} = {}", key, value);});}}
Pay attention to a question here: why an extra dynamic is designed here. Prefix configuration, this is because the blogger triggered a hidden problem in the apollo configuration listener during the test, resulting in the failure of the Apollo dynamic listener. SystemProperties is the highest priority for Apollo configuration loading. When the configuration changes, apollo will overwrite SystemProperties to the configuration before comparing whether there are any updates in this configuration release. Because we loaded the relevant configuration into the SystemProperties from the beginning, each change will be overwritten to the previous value, causing the update judgment to be invalidated and unable to enter the listener. If you want to update dynamically, you need to maintain a copy of the configuration of apollo and the mapping in SystemProperties, rather than being consistent, so that every time you modify apollo, you can remove the prefix that maintains the mapping, and then update the value to SystemProperties dynamically. The current design supports both one-time loading of all native configurations and support for dynamic. Dynamic loading of prefix assembly original configuration
Configuration example
# load hystrix.command.default.execution.timeout.enabled at one time during initialization = true# dynamically effective every modification dynamic.hystrix.command.default.execution.timeout.enabled = true this article on "what is the difference between Apollo and Archaius in hystrix configuration" ends here, thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what is the difference between Apollo and Archaius in hystrix configuration". If you want to learn more, you are welcome to follow the industry information channel.
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.