[英]Spring Cloud Load Balance and Feign Client
我一直在使用spring-clound-openfeign
和 Consul 作為服務注冊中心和 Ribbon 作為負載均衡器。 我目前正在使用 spring-boot 2.3.10.RELEASE。
我真的很喜歡 spring-cloud-feign-inheritance 支持,據我所知,它允許我編寫服務器端和客戶端使用的單個接口。
從 spring-boot 2.4.x
開始,spring 團隊建議將 Ribbon 替換為spring-clould-loadbanced
作為替代,因為 Ribbon 不再維護。
如果我有一個界面,請說:
interface Greeting {
@GetMapping
hello(String name);
}
通過使用 Spring Openfeign + Ribbon + Consul 我可以擴展它:
@FeignClient(name="my-service-id")
interface GreetingClient extends Greeting { }
有了這個,我將有一個具有負載平衡功能的客戶端實現。
我仍然可以達到相同的結果, spring-cloud-openfeign
與spring-clould-loadbalancer
或我真的需要工作, RestTemplate
或DiscoveryClient
有我的API的客戶端?
由於我在其他任何地方都找到了合理的答案,因此非常感謝您對這一切的全面了解。
如果你想像ribbon那樣工作,需要將spring cloud loadbalancer連接到consul。 您可以閱讀如何將 spring cloud loadbalanncer 連接到鏈接https://docs.spring.io/spring-cloud-commons/docs/current/reference/html/#serviceregistry
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.