[英]how to get feign client name and url both dynamically in spring boot Java
我是假裝客戶端實現的新手,我有以下當前實現的代碼。
FeignPaymentAbcService:
@FeignClient(name= "abc-service", url="abc url")
public interface FeignPaymentAbcService{
//methods
}
invoking call :
(feignPaymentAbcService.someFunctionality("some input")).getBody();
將來可能會有多個偽造服務,如 feignPaymentAbcService、feignPaymentxyz 服務等,因此根據服務,它應該獲得偽造的客戶端名稱和正在運行服務的 url。 基本上想以動態方式制作。
有人可以建議任何方法嗎?
您可以使用 Feign 以及 Ribbon 和 Eureka 服務器來動態獲取 url 以及服務器(或 url 列表,具體取決於實例)
@FeignClient(name= "abc-service")
@RibbonClient(name = "abc-service")
但名稱必須存在,以便從 app.properties 文件中識別特定服務。 需要為eureka server & Ribbon Load balancer添加相應的依賴,需要在application.properties中配置
您可以在此處查找我的示例代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.