W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
您是否要使用非JVM語言來利用Eureka,Ribbon和Config Server?Spring Cloud Netflix Sidecar的靈感來自Netflix Prana。 它包括一個(gè)HTTP API,用于獲取給定服務(wù)的所有實(shí)例(按主機(jī)和端口)。您也可以通過嵌入式Zuul代理來代理服務(wù)調(diào)用,該代理從Eureka獲取其路由條目。可以直接通過主機(jī)查找或通過Zuul代理訪問Spring Cloud Config服務(wù)器。非JVM應(yīng)用程序應(yīng)實(shí)施運(yùn)行狀況檢查,以便Sidecar可以向Eureka報(bào)告應(yīng)用程序是啟動(dòng)還是關(guān)閉。
要在項(xiàng)目中包含Sidecar,請(qǐng)使用組ID為org.springframework.cloud
且工件ID為??spring-cloud-netflix-sidecar
的依賴項(xiàng)。
要啟用Sidecar,請(qǐng)使用@EnableSidecar
創(chuàng)建一個(gè)Spring Boot應(yīng)用程序。該注釋包括@EnableCircuitBreaker
,@EnableDiscoveryClient
和@EnableZuulProxy
。
在與非JVM應(yīng)用程序相同的主機(jī)上運(yùn)行結(jié)果應(yīng)用程序。
要配置側(cè)車,請(qǐng)將sidecar.port
和sidecar.health-uri
添加到application.yml
。sidecar.port
屬性是非JVM應(yīng)用程序偵聽的端口。
這樣Sidecar可以正確地向Eureka注冊(cè)應(yīng)用程序。sidecar.secure-port-enabled
選項(xiàng)提供了一種啟用流量安全端口的方法。sidecar.health-uri
是在非JVM應(yīng)用程序上可訪問的URI,它模仿Spring Boot運(yùn)行狀況指示器。
它應(yīng)該返回類似于以下內(nèi)容的JSON文檔:
health-uri-document。
{ "status":"UP" }
以下application.yml示例顯示了Sidecar應(yīng)用程序的示例配置:
application.yml。
server: port: 5678 spring: application: name: sidecar sidecar: port: 8000 health-uri: http://localhost:8000/health.json
DiscoveryClient.getInstances()
方法的API為/hosts/{serviceId}
。以下針對(duì)/hosts/customers
的示例響應(yīng)在不同的主機(jī)上返回兩個(gè)實(shí)例:
/ hosts / customers。
[ { "host": "myhost", "port": 9000, "uri": "http://myhost:9000", "serviceId": "CUSTOMERS", "secure": false }, { "host": "myhost2", "port": 9000, "uri": "http://myhost2:9000", "serviceId": "CUSTOMERS", "secure": false } ]
非JVM應(yīng)用程序(如果Sidecar位于端口5678上)可通過http://localhost:5678/hosts/{serviceId}
訪問此API。
Zuul代理會(huì)自動(dòng)將Eureka中已知的每個(gè)服務(wù)的路由添加到/<serviceId>
,因此可以在/customers
中使用客戶服務(wù)。非JVM應(yīng)用程序可以在http://localhost:5678/customers
上訪問客戶服務(wù)(假設(shè)Sidecar正在偵聽5678端口)。
如果Config Server已向Eureka注冊(cè),則非JVM應(yīng)用程序可以通過Zuul代理對(duì)其進(jìn)行訪問。如果ConfigServer的serviceId
為configserver
并且Sidecar在端口5678上,則可以在http:// localhost:5678 / configserver上對(duì)其進(jìn)行訪問。
非JVM應(yīng)用程序可以利用Config Server返回YAML文檔的功能。例如,調(diào)用https://sidecar.local.spring.io:5678/configserver/default-master.yml 可能會(huì)導(dǎo)致YAML文檔類似于以下內(nèi)容:
eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ password: password info: description: Spring Cloud Samples url: https://github.com/spring-cloud-samples
要在使用HTTP時(shí)使運(yùn)行狀況檢查請(qǐng)求接受所有證書,請(qǐng)將sidecar.accept-all-ssl-certificates
設(shè)置為`true。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: