鍒嗗竷寮忓姩鎬侀厤缃悗娴帹鍓嶆氮 -- Nacos
Posted 鏋舵瀯甯堢ぞ鍖?/a> 鍒嗗
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鍒嗗竷寮忓姩鎬侀厤缃悗娴帹鍓嶆氮 -- Nacos相关的知识,希望对你有一定的参考价值。
馃尨 鍓嶈█
Nacos 鏄樋閲屽反宸寸殑寮€婧愮殑椤圭洰锛屽叏绉?Naming Configuration Service 锛屼笓娉ㄤ簬鏈嶅姟鍙戠幇鍜岄厤缃鐞嗛鍩熴€?/p>
Nacos 鑷村姏浜庡府鍔╂偍鍙戠幇銆侀厤缃拰绠$悊寰湇鍔°€侼acos 鎻愪緵浜嗕竴缁勭畝鍗曟槗鐢ㄧ殑鐗规€ч泦锛屽府鍔╂偍蹇€熷疄鐜板姩鎬佹湇鍔″彂鐜般€佹湇鍔¢厤缃€佹湇鍔″厓鏁版嵁鍙婃祦閲忕鐞嗐€?/p>
瀹㈡埛绔瑷€鏂归潰鐩墠鏀寔 Java锛実o 銆乸ython銆?C# 鍜?C++绛変富娴佽瑷€
鐩墠 Github涓婂凡缁忔湁杩?18K 鐨?start锛屽張鏈夐樋閲屽反宸村鏉傜殑涓氬姟鍋氳儗涔︼紝鍦ㄥ紑婧愬競鍦洪潪甯稿彈娆㈣繋銆傛渶杩戜竴娆?commits 鏃堕棿鍦?021骞?鏈?鏃ワ紝绀惧尯缁存姢鎶曞叆鍔涘害寰堝ぇ锛屼竴浜沚ug涔熻兘鍙婃椂淇銆?br>
馃尨 鏍稿績鍔熻兘
1銆佸姩鎬侀厤缃湇鍔? 鍔ㄦ€侀厤缃湇鍔¤鎮ㄨ兘澶熶互涓績鍖栥€佸閮ㄥ寲鍜屽姩鎬佸寲鐨勬柟寮忕鐞嗘墍鏈夌幆澧冪殑閰嶇疆銆傚姩鎬侀厤缃秷闄や簡閰嶇疆鍙樻洿鏃堕噸鏂伴儴缃插簲鐢ㄥ拰鏈嶅姟鐨勯渶瑕併€傞厤缃腑蹇冨寲绠$悊璁╁疄鐜版棤鐘舵€佹湇鍔℃洿绠€鍗曪紝涔熻鎸夐渶寮规€ф墿灞曟湇鍔℃洿瀹规槗銆?/p>
2銆佹湇鍔″彂鐜板強绠$悊 鍔ㄦ€佹湇鍔″彂鐜板浠ユ湇鍔′负涓績鐨勶紙渚嬪寰湇鍔″拰浜戝師鐢燂級搴旂敤鏋舵瀯鏂瑰紡闈炲父鍏抽敭銆侼acos鏀寔DNS-Based鍜孯PC-Based锛圖ubbo銆乬RPC锛夋ā寮忕殑鏈嶅姟鍙戠幇銆侼acos涔熸彁渚涘疄鏃跺仴搴锋鏌ワ紝浠ラ槻姝㈠皢璇锋眰鍙戝線涓嶅仴搴风殑涓绘満鎴栨湇鍔″疄渚嬨€傚€熷姪Nacos锛屾偍鍙互鏇村鏄撳湴涓烘偍鐨勬湇鍔″疄鐜版柇璺櫒銆?/p>
3銆佸姩鎬丏NS鏈嶅姟
閫氳繃鏀寔鏉冮噸璺敱锛屽姩鎬丏NS鏈嶅姟鑳借鎮ㄨ交鏉惧疄鐜颁腑闂村眰璐熻浇鍧囪 銆佹洿鐏垫椿鐨勮矾鐢辩瓥鐣ャ€佹祦閲忔帶鍒朵互鍙婄畝鍗曟暟鎹腑蹇冨唴缃戠殑绠€鍗旸NS瑙f瀽鏈嶅姟銆傚姩鎬丏NS鏈嶅姟杩樿兘璁╂偍鏇村鏄撳湴瀹炵幇浠NS鍗忚涓哄熀纭€鐨勬湇鍔″彂鐜帮紝浠ユ秷闄よ€﹀悎鍒板巶鍟嗙鏈夋湇鍔″彂鐜癆PI涓婄殑椋庨櫓銆?/p>
馃尨 Nacos 2.x 浼樼偣
鍦∟acos 1.X 鍩虹涓婏紝瀵归€氳灞傚仛浜嗕紭鍖栵紝鐩墠閲囩敤浜?code class="mq-24">gRPC瀹炵幇浜嗛暱杩炴帴鍜岄厤缃帹鍔紝浣跨敤闀块摼鎺ョ殑濂藉澶у箙搴﹀噺灏戜簡 1.x 杞蹇冭烦棰戠箒瀵艰嚧 JVM Full GC銆?/p>
1銆佸鎴风涓嶅啀闇€瑕佸畾鏃跺彂閫佸疄渚嬪績璺筹紝鍙渶瑕佹湁涓€涓淮鎸佽繛鎺ュ彲鐢?keepalive
娑堟伅鍗冲彲銆傞噸澶?TPS 鍙互澶у箙闄嶄綆銆?/p>
2銆乀CP 杩炴帴鏂紑鍙互琚揩閫熸劅鐭ュ埌锛屾彁鍗囧弽搴旈€熷害銆?/p>
3銆侀暱杩炴帴鐨勬祦寮忔帹閫侊紝姣?UDP 鏇村姞鍙潬锛沶io 鐨勬満鍒跺叿鏈夋洿楂樼殑鍚炲悙閲忥紝鑰屼笖鐢变簬鍙潬鎺ㄩ€侊紝鍙互鍔犻暱瀹㈡埛绔敤浜庡璐︽湇鍔″垪琛ㄧ殑鏃堕棿锛岀敋鑷冲垹闄ょ浉鍏崇殑璇锋眰銆傞噸澶嶇殑鏃犳晥 QPS 鍙互澶у箙闄嶄綆銆?/p>
4銆侀暱杩炴帴閬垮厤棰戠箒杩炴帴寮€閿€锛屽彲浠ュぇ骞呯紦瑙?TIME_WAIT
闂銆?/p>
5銆佺湡瀹炵殑闀胯繛鎺ワ紝瑙e喅閰嶇疆妯″潡 GC 闂銆?/p>
6銆佹洿缁嗙矑搴︾殑鍚屾鍐呭锛屽噺灏戞湇鍔¤妭鐐归棿鐨勯€氫俊鍘嬪姏銆?/p>
馃尨 Show me the code
澶栭儴渚濊禆锛?/strong>
Spring Boot 宸茬粡涓?Nacos 灏佽浜唖tarter缁勪欢锛屽彧闇€鍦?pom.xml 鏂囦欢涓坊鍔爅ar鐗堟湰渚濊禆鍗冲彲锛?/p>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-actuator</artifactId>
<version>0.2.1</version>
</dependency>
閰嶇疆鏂囦欢锛?/strong>
鍦ㄩ厤缃枃浠?application.yaml 涓厤缃?Nacos 鐨勭浉鍏冲弬鏁帮紝鍏蜂綋鍐呭濡備笅锛?/p>
nacos:
config:
server-addr: 127.0.0.1:8848
灏卞儚Maven鐢?code class="mq-49">groupId銆?code class="mq-50">artifactId銆?code class="mq-51">version涓夎€呮潵瀹氫綅涓€涓?code class="mq-52">jar鍖呭湪浠撳簱涓殑浣嶇疆涓€鏍枫€侼acos涔熸彁渚涗簡 Namespace (鍛藉悕绌洪棿) 銆丏ata ID (閰嶇疆闆咺D)銆?Group (缁? 鏉ョ‘瀹氫竴涓厤缃枃浠躲€?/p>
StartApplication 鍚姩绫伙紝娣诲姞dataId锛?/strong>
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class})
@NacosPropertySource(dataId = "bulking-nacos-example", autoRefreshed = true)
public class StartApplication {
public static void main(String[] args) {
SpringApplication.run(StartApplication.class, args);
}
}
nacos鎻愪緵浜嗘敞瑙f柟寮忥紝瀹炴椂鍔ㄦ€佽幏鍙栭厤缃」鏈€鏂板€?/strong>
@Controller
@RequestMapping("config")
public class ConfigController {
@NacosValue(value = "${useLocalCache}", autoRefreshed = true)
private boolean useLocalCache;
@RequestMapping(value = "/get", method = GET)
@ResponseBody
public boolean get() {
return useLocalCache;
}
}
馃尨 鎿嶄綔婕旂ず
绠$悊鍚庡彴锛?/strong>
鏂板鍔ㄦ€侀厤缃?/strong>褰撳簲鐢ㄥ惎鍔ㄦ椂锛屼細灏嗗綋鍓嶈妭鐐规敞鍐屽埌nacos涓?/p>
棣栨璁块棶锛?/span>http://localhost:9071/config/get
杩斿洖缁撴灉锛?/p>
true
灏唍acos涓?
Data Id
锛?code class="mq-94">bulking-nacos-example 涓殑useLocalCache
璁剧疆鎴?code class="mq-96">false婕旂ず宸ョ▼鍦ㄤ笉閲嶅惎鐨勬儏鍐典笅锛岃兘瀹炴椂鎰熺煡閰嶇疆椤圭殑鍙樺寲銆?/p>
馃尨 宸ョ▼浠g爜
https://github.com/aalansehaiyang/spring-boot-bulking
妯″潡锛歴pring-boot-bulking-naco
以上是关于鍒嗗竷寮忓姩鎬侀厤缃悗娴帹鍓嶆氮 -- Nacos的主要内容,如果未能解决你的问题,请参考以下文章
浣犺繕鍦ㄧ湅鍒嗗竷寮忓井鏈嶅姟鏋舵瀯锛熻繖绡囨枃绔犺冻澶熻浣犲涔犲埌
瀹夋帓锛岃胺绮掑晢鍩巎ava鍒嗗竷寮忓紑鍙戝熀纭€绡囬珮绾х瘒涓庨珮鍙敤闆嗙兢鏋舵瀯绡?020