Spring Cloud 参考文档(使用Sidecar支持多语言)

栏目: Java · 发布时间: 6年前

内容简介:你是否有希望利用Eureka、Ribbon和Config Server的非JVM语言?Spring Cloud Netflix Sidecar的灵感来自要在项目中包含Sidecar,请使用组ID为要启用Sidecar,请使用

使用Sidecar支持多语言

你是否有希望利用Eureka、Ribbon和Config Server的非JVM语言?Spring Cloud Netflix Sidecar的灵感来自 Netflix Prana ,它包含一个HTTP API,用于获取给定服务的所有实例(按主机和端口)。你还可以通过嵌入式Zuul代理代理服务调用,该代理从Eureka获取其路由条目,可以通过主机查找或Zuul代理直接访问Spring Cloud Config Server,非JVM应用程序应实现健康检查,以便Sidecar可以向Eureka报告应用程序是启动还是关闭。

要在项目中包含Sidecar,请使用组ID为 org.springframework.cloud 和工件ID spring-cloud-netflix-sidecar 的依赖项。

要启用Sidecar,请使用 @EnableSidecar 创建Spring Boot应用程序,此注解包括 @EnableCircuitBreaker@EnableDiscoveryClient@EnableZuulProxy ,在与非JVM应用程序相同的主机上运行生成的应用程序。

要配置Sidecar,请将 sidecar.portsidecar.health-uri 添加到 application.ymlsidecar.port 属性是非JVM应用程序侦听的端口,这样Sidecar可以正确地向Eureka注册应用程序, sidecar.health-uri 是可在非JVM应用程序上访问的URI,它模仿Spring Boot健康指示器,它应该返回类似于以下内容的JSON文档:

health-uri-document

{
  "status":"UP"
}

以下 application.yml 示例显示了Sidecar应用程序的示例配置:

server:
  port: 5678
spring:
  application:
    name: sidecar

sidecar:
  port: 8000
  health-uri: http://localhost:8000/health.json

DiscoveryClient.getInstances() 方法的API是 /hosts/{serviceId} ,以下针对 /hosts/customers 的示例响应返回在不同主机上的两个实例:

/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应用程序(如果sidecar在端口5678上)可以在 http://localhost:5678/hosts/{serviceId} 访问此API。

Zuul代理自动将Eureka中已知的每个服务的路由添加到 /<serviceId> ,因此customers服务可在 /customers 处获得,非JVM应用程序可以访问位于 http://localhost:5678/customers 的customer服务(假设sidecar正在侦听端口5678)。

如果配置服务器已在Eureka中注册,则非JVM应用程序可以通过Zuul代理访问它,如果ConfigServer的 serviceIdconfigserver 且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


以上所述就是小编给大家介绍的《Spring Cloud 参考文档(使用Sidecar支持多语言)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Four

The Four

Scott Galloway / Portfolio / 2017-10-3 / USD 28.00

NEW YORK TIMES BESTSELLER USA TODAY BESTSELLER Amazon, Apple, Facebook, and Google are the four most influential companies on the planet. Just about everyone thinks they know how they got there.......一起来看看 《The Four》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具