你是否有但愿利用Eureka、Ribbon和Config Server的非JVM语言?Spring Cloud Netflix Sidecar的灵感来自Netflix Prana,它包含一个HTTP API,用于获取给定服务的全部实例(按主机和端口)。你还能够经过嵌入式Zuul代理代理服务调用,该代理从Eureka获取其路由条目,能够经过主机查找或Zuul代理直接访问Spring Cloud Config Server,非JVM应用程序应实现健康检查,以便Sidecar能够向Eureka报告应用程序是启动仍是关闭。git
要在项目中包含Sidecar,请使用组ID为org.springframework.cloud
和工件IDspring-cloud-netflix-sidecar
的依赖项。github
要启用Sidecar,请使用@EnableSidecar
建立Spring Boot应用程序,此注解包括@EnableCircuitBreaker
、@EnableDiscoveryClient
和@EnableZuulProxy
,在与非JVM应用程序相同的主机上运行生成的应用程序。spring
要配置Sidecar,请将sidecar.port
和sidecar.health-uri
添加到application.yml
,sidecar.port
属性是非JVM应用程序侦听的端口,这样Sidecar能够正确地向Eureka注册应用程序,sidecar.health-uri
是可在非JVM应用程序上访问的URI,它模仿Spring Boot健康指示器,它应该返回相似于如下内容的JSON文档:json
health-uri-document服务器
{ "status":"UP" }
如下application.yml
示例显示了Sidecar应用程序的示例配置:app
server: port: 5678 spring: application: name: sidecar sidecar: port: 8000 health-uri: http://localhost:8000/health.json
DiscoveryClient.getInstances()
方法的API是/hosts/{serviceId}
,如下针对/hosts/customers
的示例响应返回在不一样主机上的两个实例:ide
/hosts/customersui
[ { "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应用程序(若是sidecar在端口5678上)能够在http://localhost:5678/hosts/{serviceId}
访问此API。url
Zuul代理自动将Eureka中已知的每一个服务的路由添加到/<serviceId>
,所以customers服务可在/customers
处得到,非JVM应用程序能够访问位于http://localhost:5678/customers
的customer服务(假设sidecar正在侦听端口5678)。代理
若是配置服务器已在Eureka中注册,则非JVM应用程序能够经过Zuul代理访问它,若是ConfigServer的serviceId
是configserver
且Sidecar在端口5678上,则能够在http://localhost:5678/configserver
上访问它。
非JVM应用程序能够利用Config Server返回YAML文档的能力,例如,调用http://sidecar.local.spring.io:5678/configserver/default-master.yml可能会致使YAML文档相似于如下内容:
eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/ password: password info: description: Spring Cloud Samples url: https://github.com/spring-cloud-samples
要在使用HTTPs时将健康检查请求设置为接受全部证书,请将sidecar.accept-all-ssl-certificates
设置为true
。