docs/Spring全家桶/SpringCloudAlibaba源码分析/SpringCloudAlibabaNacos源码分析:服务注册.md
ͻԴӴʽԴ
<plugin> <groupId>org.apache.maven.plugins</groupId> maven-source-plugin <version>3.2.1</version> <configuration> true </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin>
Ȼ
mvn install -DskipTests
ǻԴǻͨԴķʽ ͨdebugķʽжй̡
ǴԴĽǶһ£ϱעģ
NacosNamingService Ƿעͷص࣬ォǰķעʵķǿһʲôˣ

ƴһЩhttpעĽз֣ľ·
ǶӦ·ǻصٷĵָϵ
ãǽͲ濴ˣǿԵȥһ£
ĵø
е
ͬѧô֪ϵʹﵽǿһ鿴Դ·ǿһǶ·ҪnacosķֹܣҪǵdiscoveryİһstarterǰѧspringboot֪κstarterһиspring.factoriesΪһ
涯̬صܶ࣬NacosServiceRegistryAutoConfiguration ܷһnacosעԶ࣬
ʵ࣬ǿһNacosAUtoServiceRegistration
Զע࣬ǿԿһļɹϵһApplicationListener springɺᷢһϢapplicaitonListenerͨϢȻִеġ֪һӦô
Բ鿴ijࡣ
鿴onApplicationEventڷͻᷢһϢյϢͻbind
иif return ǾֱһǷ֧룬ķ֧ǾͲҪһ ҪߣֱӿstartûжӦĴǿԽ֧ ãstart, begininitregisterǺҪķһҪȥ
һifͲÿڶifҪΪû㿴register()ӦþΪDz鿴ע̡
Ҫ֪SpringBootԶװĻ֪ʶҪ֪Springֵ ֪ʶ
Nacos߲֧첽ڴ
ղڷṩ潲ݣǷעһ
instanceʵһspringmvccontrollerǿȫ ControllerinstanceʵɣInstanceController
֮ǰõpostDz鿴postdelete,update...,ʲô restFul
ǷûжӦDefaultGroupڷעͷֵgroupDzõġõĻֻԼĹ淶ͷġڷעͷԴжûáռ䣬ȻDzתΪʵǷģеģ͡
ǿһעʵʲô עעinstanceǾΧзDzǾaddInstance
createEmptyService
1ȡservice λȡһΪգǿԽȥһ
עǰ˵nacosģ͡ԲοͼmapǶӦע
÷ͳʼ
ʼ
ǸscheduleNamingHealthһʱֻҪһtaskͿ
taskҪһrun
ǿǻȡеʵԵȥһ¡
ǰʱ - ϴʱ 15 ʵΪǽ 30ûյֱ
ãǻرãcreateEmtyServiceǴһշǵʵDzǻעᵽ棬
ǿԿһ·ģͣǰ˵һ
ռ cluster Ⱥ
ȺжӦʵ
ǿһaddinstance
Ӧkey:
String key = KeyBuilder.buildInstanceListKey(namespaceId, serviceName, ephemeral);
//ȡעʵIP˿б List<Instance> instanceList = addIpAddresses(service, ephemeral, ips);
ǽĿһ£Ƿadd,removeƳʵ
ҪдעipsǾ͵ipsʾȻѭinstanceǿԿƳʹmapƳȥinstanceMapһ£ڷء
࣬ǿԲ²һ£debugȥȻ࣬ǵһ£ĵط
ָƣ
ãȫһ£
֪ǰ˵ephemeraltrueѡһ ʣ
ӦõEphemeralConsistencyServiceӦputEphemeralConsistencyServiceֻһӿڣӦõöӦʵʵ
ǿһonput
ڷŵУ
ǰѺĵŵblockquene棬Ҳһ
עĹ̾ôһսעŵǵеУŵɫ֮оͷˡǷŵ֮зС
עNotifierһ̣߳ʦһɣһ߳̾ҪrunΪrun ִдĵط
ѭݴϵĴͻעϢʵֺ첽עϢ
̻߳һֱתһֱУ˵ҵˣã㿴쳣ҲԵˣһֱУûócpu
עṹķ
ȵǸchangeʱǾͽonChangeǸǽserviceȥ
ͲÿˣȿȨأȨشڶٵʱֵȨСڶٵʱһСֵȻǺĵķupdateIP
updateIPsʲôأ ľұҪעʵȻͷŵǵclusterMap
ǵҿܾˣʲôʱ̣߳ʵʱϢأ ̴һڿŸNotifierΪһ̣߳ᶪһ̳߳нУǿһʵģ
ǿעǵspringһгʼ֮еõģǿһinitʲô
һScheduled̳߳أ

Ҳڶʼʱͽһ̳߳أȥnotifierӦķrunrunġͻʵʱ첽СдĺôǽдʹȫˡͨܵڴУ飬ĺô1
https://lijunyi.xyz/docs/SpringCloud/SpringCloud.html#_2-2-x-%E5%88%86%E6%94%AF https://mp.weixin.qq.com/s/2jeovmj77O9Ux96v3A0NtA https://juejin.cn/post/6931922457741770760 https://github.com/D2C-Cai/herring http://c.biancheng.net/springcloud https://github.com/macrozheng/springcloud-learning