springcloud常見問題總結

  1. Eureka
    1. Eureka Environment的配置:

eureka.environment: 字符串

參考文檔:

https://github.com/Netflix/eureka/wiki/Configuring-Eureka

 

    1. Eureka DataCenter的配置

eureka.datacenter: cloud

https://github.com/Netflix/eureka/wiki/Configuring-Eureka

這邊說:配置-Deureka.datacenter=cloud,這樣eureka將會知道是在AWS雲上

 

    1. Eureka開啓自我保護的提示

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.

 

    1. Eureka註冊服務慢的問題如何解決?

eureka.instance.leaseRenewalIntervalInSeconds

參考文檔:

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 配置,這將加快客戶端連接到其他服務的過程。在生產中,最好堅持使用默認值,因爲在服務器內部有一些計算,他們對續約做出假設。

 

    1. 如何解決Eureka Server不踢出已關停的節點的問題?

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

 

 

    1. Eureka配置instanceId顯示IP

eureka:

  client:

    serviceUrl:

      defaultZone: http://localhost:8761/eureka/

  instance:

    preferIpAddress: true

    instance-id: ${spring.cloud.client.ipAddress}:${server.port}

 

    1. Eureka配置最佳實踐總結

https://github.com/spring-cloud/spring-cloud-netflix/issues/203

 

 

  1. Ribbon
    1. 自定義配置時,@Configuration和@ComponentScan包不應重疊
    2. 使用RestTemplate時,想要獲得一個List時,應該用數組,而不應該直接用List

 

  1. Feign
    1. 自定義配置時,@Configuration和@ComponentScan包不應重疊
    2. @FeignClient所在的接口中,不支持@GetMapping等組合註解
    3. 使用@PathVariable時,需要指定其value
    4. Feign暫不支持複雜對象作爲一個參數

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章