我試圖從我的一個微服務中尋找外部服務。我正在使用Spring Cloud,Eureka的註冊表和Spring引導作爲主要框架。使用Spring Cloud從微服務命中外部IP
Map<String, String> urlVariables = new HashMap<>();
urlVariables.put("ip_address", IP);
urlVariables.put("port", PORT);
ResponseObject state =
restTemplate.getForObject("http://{ip_address}:{port}/state/", ResponseObject.class, urlVariables);
從我所看到的,春天的雲注入絲帶至於其餘的模板中的HTTP客戶端,當我嘗試打這個IP(如:193.172.x.x
)它產生以下錯誤:
java.lang.IllegalStateException: No instances available for 193.172.x.x at org.springframework.cloud.netflix.ribbon.RibbonClientHttpRequestFactory.createRequest(RibbonClientHttpRequestFactory.java:64) at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:76) at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:567) at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:540) at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:247)
看起來Ribbon正在嘗試使用該名稱來查找微服務實例,而不是向外看。有沒有辦法配置功能區來查找外部IP,還是僅用於內部使用?
它確實有效,但只有當我禁用尤里卡。不幸的是,我需要尤里卡以及這項服務。有沒有什麼辦法可以讓兩者同時工作? –
是的,使用'@ LoadBalanced'作爲像Marcin那樣的功能區,並且將非eureka休息模板標記爲'@ Primary'。 – spencergibb