日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Eurek Ribbon Feign常见问题及解决

發(fā)布時(shí)間:2024/4/13 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Eurek Ribbon Feign常见问题及解决 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Eureka的首頁(yè)我們可以看到System Status,Environment,test,那我們?cè)趺慈バ薷倪@些信息呢,在Spring Cloud文檔里面是沒(méi)有提到這一塊的,但是在Eureka的文檔里面是有看到Configuring Eureka Clienthttps://github.com/Netflix/eureka/wiki/Configuring-EurekaIf you are running in the cloud environment, you will need to pass in the java commandline property -Deureka.datacenter=cloud so that the Eureka Client/Server knows to initialize the information specific to AWS cloud.你啟動(dòng)的時(shí)候用-D的一個(gè)參數(shù),你可以指定-Deureka.datacenter=cloud,Eureka Client/Server他就知道,去初始化這個(gè)信息,AWS要的一些信息eureka.datacenter=cloudeureka.environment=productlocalhost:8761/ server.port=8761 #eureka.instance.hostname=eureka1#spring.application.name=microservice-discovery-eureka #eureka.server.evictionIntervalTimerInMs=60000 eureka.client.serviceUrl.defaultZone=http://admin:1234@localhost:8761/eureka #eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka eureka.client.registerWithEureka=false eureka.client.fetchRegistry=false#eureka.server.enableSelfPreservation=truesecurity.basic.enabled=true security.user.name=admin security.user.password=1234spring.http.encoding.charset=UTF-8 spring.http.encoding.enabled=true spring.http.encoding.force=truelogging.level.com.learn=trace logging.file=springboot.log logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n logging.pattern.file=%d{yyyy-MM-dd} ==== [%thread] %-5level ==== %logger{50} ==== %msg%neureka.datacenter=cloud eureka.environment=product

Eureka他有的時(shí)候會(huì)出現(xiàn)一個(gè)紅字,相信大家都有遇到過(guò),那這個(gè)紅字是什么呢,他的紅字內(nèi)容是這個(gè)東西EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.表示Eureka進(jìn)入了自動(dòng)保護(hù)模式,那什么是自我保護(hù)模式,自我保護(hù)模式有什么特性呢When the Eureka server comes up, it tries to get all of the instance registry information from a neighboring node. If there is a problem getting the information from a node, the server tries all of the peers before it gives up. If the server is able to successfully get all of the instances,it sets the renewal threshold that it should be receiving based on that information. If any time,the renewals falls below the percent configured for that value (below 85% within 15 mins), the server stops expiring instances to protect the current instance registry information.In Netflix, the above safeguard is called as self-preservation mode and is primarily used asa protection in scenarios where there is a network partition between a group of clients and the Eureka Server. In these scenarios, the server tries to protect the information it already has. There may be scenarios in case of a mass outage that this may cause the clients to get the instances that do not exist anymore. The clients must make sure they are resilient to eureka server returning an instance that is non-existent or un-responsive. The best protection in these scenarios is to timeout quickly and try other servers.https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communication他說(shuō)當(dāng)Eureka服務(wù)器啟動(dòng)時(shí),他嘗試從相鄰節(jié)點(diǎn)獲取所有實(shí)例注冊(cè)表信息,在高可用的Eureka里面,他不是會(huì)相互復(fù)制嗎,如果從節(jié)點(diǎn)獲取的信息有問(wèn)題,服務(wù)器在放棄之前嘗試所有對(duì)等體,如果服務(wù)器能夠成功獲取實(shí)例,他根據(jù)該信息設(shè)置其接收的更新閾值,在任何時(shí)間,續(xù)訂低于該值配置的百分比,服務(wù)器將停止,本應(yīng)到期的實(shí)例,按理來(lái)說(shuō)過(guò)一段時(shí)間沒(méi)有接收到心跳,他就應(yīng)該去expiring,但是在保護(hù)模式他stop expiring,這是一個(gè)Eureka Server,這是一個(gè)Eureka Client,client每30秒給server搞心跳信息,server如果沒(méi)有90秒沒(méi)有接收到心跳信息,把這個(gè)client卡擦掉,但是假設(shè)server進(jìn)入了自我保護(hù)模式,self-preservation,現(xiàn)在進(jìn)入了自我保護(hù)模式,雖然他一直沒(méi)有接收到心跳,他懷疑是eureka server本身,他可能有問(wèn)題,所以這個(gè)時(shí)候他就不把client的節(jié)點(diǎn)給踢掉了,這里有一個(gè)服務(wù)注冊(cè)節(jié)點(diǎn),服務(wù)注冊(cè)列表把client給刪掉,現(xiàn)在就不刪了,他懷疑是eureka本身出了問(wèn)題,在Netflix中,上述保護(hù)措施稱為自我保護(hù)模式,主要用戶在一組客戶端和Eureka服務(wù)器之間存在網(wǎng)絡(luò)分區(qū)的保護(hù),因?yàn)樗斜Wo(hù)模式呢,所以有的時(shí)候還比較麻煩EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE. 看到這一段,就說(shuō)明進(jìn)入保護(hù)模式了,只要進(jìn)入保護(hù)模式,但是在開發(fā)的時(shí)候,我們往往只是做測(cè)試,現(xiàn)在我想把USER給踢掉,他不踢,STS會(huì)調(diào)用SpringBoot的shutdown hook,停止的一個(gè)鉤子,鉤子會(huì)主動(dòng)地下線,你幫我下掉吧,是這個(gè)意思,netstat -ano | findstr 3306eureka他有一個(gè)配置eureka.server.enable-self-preservation 他可以把自我模式關(guān)掉,那這個(gè)時(shí)候我就可以做測(cè)試eureka.client.healthcheck.enabled = true 開啟健康檢查(需要spring-boot-starter-actuator依賴) eureka.instance.lease-renewal-interval-in-seconds =10 租期更新時(shí)間間隔(默認(rèn)30秒) eureka.instance.lease-expiration-duration-in-seconds =30 租期到期時(shí)間(默認(rèn)90秒)eureka:server:enableSelfPreservation: falseevictionIntervalTimerInMs: 4000Interval是一個(gè)定時(shí)器,但是在生產(chǎn)環(huán)境中,千萬(wàn)不要把自我保護(hù)模式關(guān)掉

eureka:instance:leaseRenewalIntervalInSeconds: 10leaseExpirationDurationInSeconds: 30注意: 更改Eureka更新頻率將打破服務(wù)器的自我保護(hù)功能 https://github.com/spring-cloud/spring-cloud-netflix/issues/373eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/instance:preferIpAddress: trueinstance-id: ${spring.cloud.client.ipAddress}:${server.port}https://github.com/spring-cloud/spring-cloud-netflix/issues/203 Documentation: changing Eureka renewal frequency *WILL* break the self-preservation feature of the server #373他說(shuō)這個(gè)東西你不要去修改,它會(huì)打破自我保護(hù)的特性,我們?cè)谶@邊是應(yīng)用名稱,應(yīng)用的端口,那你這個(gè)時(shí)候就得關(guān)閉自我保護(hù)的模式,我這邊想顯示IP:端口怎么辦,instance-id: ${spring.cloud.client.ipAddress}:${server.port}我們可以用這個(gè)配置microservice-simple-provider-user:10.40.8.144:7900我立馬就知道應(yīng)用的IP是多少,端口是多少,這只是一個(gè)拓展,1.7. Eureka配置最佳實(shí)踐總結(jié) https://github.com/spring-cloud/spring-cloud-netflix/issues/203配置談不上什么最佳實(shí)踐,因?yàn)槿魏我环N配置他不可能滿足所有的要求,那就要看你這個(gè)配置能否滿足要求,能滿足你的要求就是最佳實(shí)踐,只是做一個(gè)參考,像github標(biāo)注為documention的,一般都是質(zhì)量還不錯(cuò)的文檔,可以做一些參考 第二個(gè)就是Ribbon,@Configuration和@ComponentScan這個(gè)包不能夠重疊,RestTemplate有一個(gè)坑,其實(shí)它不是Ribbon的坑,它是RestTemplate的坑@GetMapping("list-all")public List<User> listAll() {ArrayList<User> list = Lists.newArrayList();User user = new User(1L, "zhangsan");User user2 = new User(2L, "zhangsan");User user3 = new User(3L, "zhangsan");list.add(user);list.add(user2);list.add(user3);return list;}localhost:7900/list-all[{"id":1,"username":null,"name":"zhangsan","age":null,"balance":null},{"id":2,"username":null,"name":"zhangsan","age":null,"balance":null},{"id":3,"username":null,"name":"zhangsan","age":null,"balance":null} ]在ribbon項(xiàng)目里面@GetMapping("/list-all")public List<User> listAll() {// wrong// List<User> list = this.restTemplate.getForObject("http://microservice-provider-user/list-all", List.class);// for (User user : list) {// System.out.println(user.getId());// }// rightUser[] users = this.restTemplate.getForObject("http://microservice-simple-provider-user/list-all", User[].class);List<User> list2 = Arrays.asList(users);for (User user : list2) {System.out.println(user.getId());}return list2;}localhost:8010/list-all[{"id":1,"username":null,"name":"zhangsan","age":null,"balance":null},{"id":2,"username":null,"name":"zhangsan","age":null,"balance":null},{"id":3,"username":null,"name":"zhangsan","age":null,"balance":null} ]

?

總結(jié)

以上是生活随笔為你收集整理的Eurek Ribbon Feign常见问题及解决的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。