eureka.environment: 字符串
參考文檔:git
https://github.com/Netflix/eureka/wiki/Configuring-Eurekagithub
eureka.datacenter: cloud
https://github.com/Netflix/eureka/wiki/Configuring-Eurekaspring
這邊說:配置-Deureka.datacenter=cloud,這樣eureka將會知道是在AWS雲上數組
用點的方式寫法與縮進能夠同時使用緩存
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 Server之間存在網絡分區場景下的保護。一旦進入保護模式,Eureka Server將會嘗試保護其服務註冊表中的信息,再也不刪除服務註冊表中的數據(也就是不會註銷任何微服務)。 網絡
https://github.com/Netflix/eureka/wiki/Understanding-Eureka-Peer-to-Peer-Communicationapp
eureka.instance.leaseRenewalIntervalInSecondside
參考文檔:spring-boot
http://cloud.spring.io/spring-cloud-static/Camden.SR1/#_why_is_it_so_slow_to_register_a_service
原文:
Why is it so Slow to Register a Service?
Being an instance also involves a periodic heartbeat to the registry (via the client’s serviceUrl) with default duration 30 seconds. A service is not available for discovery by clients until the instance, the server and the client all have the same metadata in their local cache (so it could take 3 heartbeats). You can change the period using eureka.instance.leaseRenewalIntervalInSeconds and this will speed up the process of getting clients connected to other services. In production it’s probably better to stick with the default because there are some computations internally in the server that make assumptions about the lease renewal period.
翻譯:
做爲實例還涉及到與註冊中心的週期性心跳,默認持續時間爲30秒(經過serviceUrl)。在實例、服務器、客戶端都在本地緩存中具備相同的元數據以前,服務不可用於客戶端發現(因此可能須要3次心跳)。你可使用eureka.instance.leaseRenewalIntervalInSeconds 配置,這將加快客戶端鏈接到其餘服務的過程。在生產中,最好堅持使用默認值,由於在服務器內部有一些計算,他們對續約作出假設。
單例STS下,正常退出是能夠剔除的,若是強制關閉,是不剔除的
集羣下,
server端:
eureka.server.enable-self-preservation (設爲false,關閉自我保護主要)
eureka.server.eviction-interval-timer-in-ms 清理間隔(單位毫秒,默認是60*1000)
client端:
eureka.client.healthcheck.enabled = true 開啓健康檢查(須要spring-boot-starter-actuator依賴) eureka.instance.lease-renewal-interval-in-seconds =10 租期更新時間間隔(默認30秒) eureka.instance.lease-expiration-duration-in-seconds =30 租期到期時間(默認90秒)
示例:
服務器端配置:
eureka: server: enableSelfPreservation: false evictionIntervalTimerInMs: 4000
客戶端配置:
eureka: instance: leaseRenewalIntervalInSeconds: 10 leaseExpirationDurationInSeconds: 30
注意:更改Eureka更新頻率將打破服務器的自我保護功能,生產模式不容許關閉
https://github.com/spring-cloud/spring-cloud-netflix/issues/373
在Spring Cloud中,服務的Instance ID的默認值是${spring.cloud.client.hostname}:${spring.application.name}:${spring.application.instance_id:${server.port}}
,也就是機器主機名:應用名稱:應用端口
。所以在Eureka Server首頁中看到的服務的信息相似以下:itmuch:microservice-provider-user:8000
。若是想要自定義這部分的信息怎麼辦?
eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ instance: preferIpAddress: true instance-id: ${spring.cloud.client.ipAddress}:${server.port}
https://github.com/spring-cloud/spring-cloud-netflix/issues/203
2.1. 自定義配置時,@Configuration和@ComponentScan包不該重疊
2.2. 使用RestTemplate時,想要得到一個List時,應該用數組,而不該該直接用List
// wrong // List<User> list = restTemplate.getForObject("http://microservice-provider-user/list-all",List.class); // for (User u : list) { // System.out.println(u); // } // right User[] users = restTemplate.getForObject("http://microservice-provider-user/list-all", User[].class); List<User> list2 = Arrays.asList(users); return list2;
3.1. 自定義配置時,@Configuration和@ComponentScan包不該重疊
3.2. @FeignClient所在的接口中,不支持@GetMapping等組合註解
3.3. 使用@PathVariable時,須要指定其value
3.4. Feign暫不支持複雜對象做爲一個參數