1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

merge from 2.2.4.RELEASE

This commit is contained in:
theonefx
2021-01-18 17:30:10 +08:00
134 changed files with 1467 additions and 1214 deletions

View File

@@ -6,7 +6,9 @@
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-cloud-alibaba-docs</artifactId>

View File

@@ -10,7 +10,7 @@ Spring Cloud Alibaba BOM 包含了它所使用的所有依赖的版本。
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.3.RELEASE</version>
<version>2.1.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@@ -229,7 +229,7 @@ in develop-env enviroment; user name :nacos-config-yaml-update; age: 68
spring.profiles.active=product
----
同时生产环境上 Nacos 需要添加对应 DataId 的基础配置。例如,在生环境下的 Naocs 添加了DataId为nacos-config-product.yaml的配置
同时生产环境上 Nacos 需要添加对应 DataId 的基础配置。例如,在生环境下的 Naocs 添加了DataId为nacos-config-product.yaml的配置
[source,subs="normal"]
----
@@ -415,8 +415,8 @@ Endpoint 暴露的 json 中包含了三种属性:
|===
|配置项 |Key |默认值 |说明
|服务端地址|`spring.cloud.nacos.config.server-addr`|| Nacos Server 启动监听的ip地址和端口
|配置对应的 DataId|`spring.cloud.nacos.config.name`|| 先取 prefix name最后取 spring.application.name
|配置对应的 DataId|`spring.cloud.nacos.config.prefix`|| 先取 prefix name最后取 spring.application.name
|配置对应的 DataId|`spring.cloud.nacos.config.name`|| 先取 prefix name最后取 spring.application.name
|配置对应的 DataId|`spring.cloud.nacos.config.prefix`|| 先取 prefix name最后取 spring.application.name
|配置内容编码|`spring.cloud.nacos.config.encode`||读取的配置内容对应的编码
|GROUP|`spring.cloud.nacos.config.group`|`DEFAULT_GROUP`|配置对应的组
|文件扩展名|`spring.cloud.nacos.config.fileExtension`|`properties`|配置项对应的文件扩展名,目前支持 properties 和 yaml(yml)

View File

@@ -1,10 +1,11 @@
== Spring Cloud Alibaba Sidecar
`Spring Cloud Alibaba Sidecar` 是一个用来快速**完美整合** Spring Cloud 与 *异构微服务* 的框架,灵感来自
https://github.com/spring-cloud/spring-cloud-netflix/tree/master/spring-cloud-netflix-sidecar[Spring Cloud Netflix Sidecar] 。目前支持的服务发现组件:
`Spring Cloud Alibaba Sidecar` 是一个用来快速**完美整合** Spring Cloud
与 *异构微服务* 的框架,灵感来自
https://github.com/spring-cloud/spring-cloud-netflix/tree/master/spring-cloud-netflix-sidecar[Spring
Cloud Netflix Sidecar] 。目前支持的服务发现组件:
* Nacos
* Consul
=== 术语
@@ -25,26 +26,42 @@ https://github.com/spring-cloud/spring-cloud-netflix/tree/master/spring-cloud-ne
原因有两点:
* Spring Cloud子项目 `Spring Cloud Netflix Sidecar` 是可以快速整合异构微服务的。然而Sidecar只支持使用Eureka作为服务发现*如果使用其他服务发现组件就抓瞎了*。
* *Sidecar是基于Zuul 1.x的*Spring Cloud官方明确声明未来将会逐步淘汰Zuul。今年早些时候我有给Spring Cloud官方提出需求希望官方实现一个基于Spring Cloud Gateway的新一代Sidecar然而官方表示并没有该计划。详见https://github.com/spring-cloud/spring-cloud-gateway/issues/735
* Spring Cloud子项目 `Spring Cloud Netflix Sidecar`
是可以快速整合异构微服务的。然而Sidecar只支持使用Eureka作为服务发现*如果使用其他服务发现组件就抓瞎了*。
* *Sidecar是基于Zuul 1.x的*Spring
Cloud官方明确声明未来将会逐步淘汰Zuul。今年早些时候我有给Spring
Cloud官方提出需求希望官方实现一个基于Spring Cloud
Gateway的新一代Sidecar然而官方表示并没有该计划。详见https://github.com/spring-cloud/spring-cloud-gateway/issues/735
既然没有,索性自己写了。
==== 为什么不用Service Mesh
* 目前Mesh主要使用场景在Kubernetes领域Istio、Linkerd大多将Kubernetes作为First Class支持虽然Istio也可部署在非Kubernetes环境而目前业界Spring Cloud应用未必有试试Mesh的环境
* 使用Alibaba Sidecar一个小组件就能解决问题了核心代码不超过200行引入整套Mesh方案颇有点屠龙刀杀黄鳝的意思。
* 目前Mesh主要使用场景在Kubernetes领域Istio、Linkerd
2等大多将Kubernetes作为First
Class支持虽然Istio也可部署在非Kubernetes环境而目前业界Spring
Cloud应用未必有试试Mesh的环境
* 使用Alibaba
Sidecar一个小组件就能解决问题了核心代码不超过200行引入整套Mesh方案颇有点屠龙刀杀黄鳝的意思。
=== 原理
* Alibaba
Sidecar根据配置的异构微服务的IP、端口等信息*将异构微服务的IP/端口注册到服务发现组件上*
* Alibaba Sidecar实现了 *健康检查* Alibaba Sidecar会定时检测异构微服务是否健康。如果发现异构微服务不健康Alibaba Sidecar会自动将代表异构微服务的Alibaba Sidecar实例下线如果异构微服务恢复正常则会自动上线。最长延迟是30秒详见 `Alibaba SidecarChecker#check`
Sidecar根据配置的异构微服务的IP、端口等信息*将异构微服务的IP/端口注册到服务发现组件上*
* Alibaba Sidecar实现了 *健康检查* Alibaba
Sidecar会定时检测异构微服务是否健康。如果发现异构微服务不健康Alibaba
Sidecar会自动将代表异构微服务的Alibaba
Sidecar实例下线如果异构微服务恢复正常则会自动上线。最长延迟是30秒详见
`Alibaba SidecarChecker#check` 。
=== 要求
* 【必须】你的异构微服务需使用HTTP通信。这一点严格来说不算要求因为Spring Cloud本身就是基于HTTP的
* 【可选】如果微服务配置了 `sidecar.health-check-url`,则表示开启健康检查,此时,你的异构微服务需实现健康检查(可以是空实现,只要暴露一个端点,返回类似 `{"status": "UP"}` 的字符串即可)。
* 【必须】你的异构微服务需使用HTTP通信。这一点严格来说不算要求因为Spring
Cloud本身就是基于HTTP的
* 【可选】如果微服务配置了 `sidecar.health-check-url`
,则表示开启健康检查,此时,你的异构微服务需实现健康检查(可以是空实现,只要暴露一个端点,返回类似
`{"status": "UP"}` 的字符串即可)。
=== 使用示例
@@ -92,7 +109,8 @@ endpoint:
show-details: always
----
+
配置比较简单就是把Alibaba Sidecar注册到Nacos上然后添加了几行Alibaba Sidecar的配置。
配置比较简单就是把Alibaba Sidecar注册到Nacos上然后添加了几行Alibaba
Sidecar的配置。
==== 异构微服务
@@ -132,13 +150,16 @@ server.listen(8060, function() {
===== 测试1Spring Cloud微服务完美调用异构微服务
为你的Spring Cloud微服务整合Ribbon然后构建 `http://node-service/\\**`,就可以请求到异构微服务的 `/**` 了。
为你的Spring Cloud微服务整合Ribbon然后构建 `http://node-service/**`
,就可以请求到异构微服务的 `/**` 了。
示例:
Ribbon请求 `http://node-service/` 会请求到 `http://localhost:8060/`,以此类推。
Ribbon请求 `http://node-service/` 会请求到 `http://localhost:8060/`
,以此类推。
至于断路器正常为你的Spring Cloud微服务整合Sentinel或者Hystirx、Resilience4J即可 。
至于断路器正常为你的Spring
Cloud微服务整合Sentinel或者Hystirx、Resilience4J即可 。
===== 测试2异构微服务完美调用Spring Cloud微服务
@@ -146,13 +167,18 @@ Ribbon请求 `http://node-service/` 会请求到 `http://localhost:8060/`,以
示例:
如果你有一个Spring Cloud微服务叫做 `spring-cloud-microservice`那么NodeJS应用只需构建 `http://localhost:8070/spring-cloud-microservice/\\**` Alibaba Sidecar就会把请求转发到 `spring-cloud-microservice` 的 `/**` 。
如果你有一个Spring Cloud微服务叫做 `spring-cloud-microservice`
那么NodeJS应用只需构建
`http://localhost:8070/spring-cloud-microservice/**` Alibaba
Sidecar就会把请求转发到 `spring-cloud-microservice` 的 `/**` 。
而Spring Cloud Gateway是整合了Ribbon的所以实现了负载均衡Spring Cloud Gateway还可以整合Sentinel或者Hystirx、Resilience4J所以也带有了断路器。
而Spring Cloud Gateway是整合了Ribbon的所以实现了负载均衡Spring Cloud
Gateway还可以整合Sentinel或者Hystirx、Resilience4J所以也带有了断路器。
=== Alibaba Sidecar优缺点分析
Alibaba Sidecar的设计和Sidecar基本一致优缺点和Sidecar的优缺点也是一样的。
Alibaba
Sidecar的设计和Sidecar基本一致优缺点和Sidecar的优缺点也是一样的。
优点:
@@ -161,5 +187,8 @@ Alibaba Sidecar的设计和Sidecar基本一致优缺点和Sidecar的优缺点
缺点:
* 每接入一个异构微服务实例都需要额外部署一个Alibaba Sidecar实例增加了部署成本虽然这个成本在Kubernetes环境中几乎可以忽略不计只需将Alibaba Sidecar实例和异构微服务作为一个Pod部署即可
* 异构微服务调用Spring Cloud微服务时本质是把Alibaba Sidecar当网关在使用经过了一层转发性能有一定下降。
* 每接入一个异构微服务实例都需要额外部署一个Alibaba
Sidecar实例增加了部署成本虽然这个成本在Kubernetes环境中几乎可以忽略不计只需将Alibaba
Sidecar实例和异构微服务作为一个Pod部署即可
* 异构微服务调用Spring Cloud微服务时本质是把Alibaba
Sidecar当网关在使用经过了一层转发性能有一定下降。

View File

@@ -8,7 +8,7 @@ If youre a Maven Central user, add our BOM to your pom.xml <dependencyManagem
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.3.RELEASE</version>
<version>2.1.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>

View File

@@ -1,6 +1,6 @@
== Introduction
Spring Cloud Alibaba aims to provide a one-stop solution for microservices development. This prjoect includes the required components for developing distributed applications and services, so that developers can develop distributed applications easily with the Spring Cloud programming models.
Spring Cloud Alibaba aims to provide a one-stop solution for microservices development. This project includes the required components for developing distributed applications and services, so that developers can develop distributed applications easily with the Spring Cloud programming models.
With Spring Cloud Alibaba, you only need to add a few annotations and configurations, and you will be able to use the distributed solutions of Alibaba for your applications, and build a distributed system of your own with Alibaba middleware.
@@ -16,4 +16,4 @@ The features of Spring Cloud Alibaba:
8. **Alibaba Cloud SchedulerX**accurate, highly reliable, and highly available scheduled job scheduling services with response time within seconds.
9. **Alibaba Cloud SMS** A messaging service that covers the globe, Alibaba SMS provides convenient, efficient, and intelligent communication capabilities that help businesses quickly contact their customers.
Spring Cloud Alibaba also provide rich https://github.com/alibaba/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples[examples].
Spring Cloud Alibaba also provide rich https://github.com/alibaba/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples[examples].

View File

@@ -159,7 +159,7 @@ NOTE: Before you start the provider application, please start Nacos first. Refer
==== Start a Consumer Application
It might not be as easy as starting a provider application, because the consumer needs to call the RESTful service of the provider. In this example, we will use the most primitive way, that is,
combining the LoadBalanceClient and RestTemolate explicitly to access the RESTful service.
combining the LoadBalanceClient and RestTemplate explicitly to access the RESTful service.
You can refer to section 1.2 for pom.xml and application.properties configurations. The following is the sample code for starting a consumer application.
NOTE: You can also access the service by using RestTemplate and FeignClient with load balancing.