In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of how to achieve nacos in SpringCloud service registration, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to achieve nacos in SpringCloud service registration. Let's take a look.
As shown in the figure below, a series of interfaces are defined under the org.springframework.cloud.spring-cloud-commons package, including a series of serviceregistry specifications, which are implemented by calling the interface through the SPI mechanism.
In the META-INF/spring.factories file of the package, you can find the item AutoServiceRegistrationAutoConfiguration.class in the value whose EnableAutoConfiguration.class is key.
Take a look at this AutoServiceRegistrationAutoConfiguration configuration class:
Accordingly, the META-INF/spring.fatories under the com.alibaba.cloud.nacos package (located in the spring-cloud-starter-nacos-discovery jar package) has a nacos service registration configuration class, as shown below:
This NacosServiceRegistryAutoConfiguration configuration class defines the implementation class of the AutoServiceRegistration interface of SpringCloud above:
Package com.alibaba.cloud.nacos.registry . / * @ author xiaojing * @ author Mercy * / @ Configuration (proxyBeanMethods = false) @ EnableConfigurationProperties@ConditionalOnNacosDiscoveryEnabled@ConditionalOnProperty (value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true) @ AutoConfigureAfter ({AutoServiceRegistrationConfiguration.class, AutoServiceRegistrationAutoConfiguration.class) NacosDiscoveryAutoConfiguration.class}) public class NacosServiceRegistryAutoConfiguration {@ Bean public NacosServiceRegistry nacosServiceRegistry (NacosDiscoveryProperties nacosDiscoveryProperties) {return new NacosServiceRegistry (nacosDiscoveryProperties) } @ Bean @ ConditionalOnBean (AutoServiceRegistrationProperties.class) public NacosRegistration nacosRegistration (ObjectProvider registrationCustomizers, NacosDiscoveryProperties nacosDiscoveryProperties, ApplicationContext context) {return new NacosRegistration (registrationCustomizers.getIfAvailable (), nacosDiscoveryProperties, context) } / * here This NacosAutoServiceRegistration is the implementation class of the AutoServiceRegistration interface * * / @ Bean @ ConditionalOnBean (AutoServiceRegistrationProperties.class) public NacosAutoServiceRegistration nacosAutoServiceRegistration (NacosServiceRegistry registry, AutoServiceRegistrationProperties autoServiceRegistrationProperties, NacosRegistration registration) {return new NacosAutoServiceRegistration (registry, autoServiceRegistrationProperties, registration) }}
The register () method in NacosAutoServiceRegistration starts to register the service, and the whole invocation process is as follows:
Continuing to trace the source, this registry () method is in the onApplicationEvent () method of the AbstractAutoServiceRegistration implements ApplicationListener class (onApplicationEvent- > bind- > start- > registey).
The heartbeat of the call defaults to 5 seconds. For more information, please see the buildBeatInfo () method in the BeatReactor class, where there is a beatInfo.setPeriod (instance.getInstanceHeartBeatInterval ()). Here we get a constant of 5s.
In addition, the implementation of the NamingClientProxy interface in the last step above is as follows, using the delegate pattern (delegate), also known as the proxy pattern. :
This is the end of the article on "how to implement nacos in SpringCloud service registration". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to realize nacos in SpringCloud service registration". If you want to learn more knowledge, 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.