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

sync & commit in finchley

This commit is contained in:
fangjian0423
2019-10-30 13:10:10 +08:00
parent 6be45914c8
commit 15465b5612
436 changed files with 7099 additions and 3202 deletions

View File

@@ -93,3 +93,4 @@ access-key 和 secret-key 则是阿里云账号的 AK/SK需要首先注册阿
namespace 是阿里云 EDAS 产品的概念,用于隔离不同的环境,比如测试环境和生产环境。要获取 namespace 需要 https://common-buy.aliyun.com/?spm=5176.11451019.0.0.6f5965c0Uq5tue&commodityCode=edaspostpay#/buy[开通 EDAS 服务],按量计费模式下开通是免费的,开通以后进入 https://edas.console.aliyun.com/#/namespaces?regionNo=cn-hangzhou[EDAS控制台],即可看到对应的 namespace比如 cn-hangzhou。
NOTE: EDAS 提供应用托管服务,如果你将应用托管到 EDAS那么 EDAS 将会自动为你填充所有配置。

View File

@@ -20,3 +20,4 @@ Spring Cloud Alibaba BOM 包含了它所使用的所有依赖的版本。
在下面的章节中,假设您使用的是 Spring Cloud Alibaba bom相关 starter 依赖将不包含版本号。

View File

@@ -1,4 +1,4 @@
## 介绍
== 介绍
Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。此项目包含开发分布式应用服务的必需组件,方便开发者通过 Spring Cloud 编程模型轻松使用这些组件来开发分布式应用服务。

View File

@@ -44,7 +44,7 @@ image::https://img.alicdn.com/tfs/TB1dyWJbQL0gK0jSZFtXXXQCXXa-2788-1086.png[]
* pom.xml的配置。一个完整的 pom.xml 配置如下所示:
.pom.xml
[source,xml,indent=0]
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

View File

@@ -1,6 +1,6 @@
== Spring Cloud Alibaba RocketMQ Binder
### RocketMQ 介绍
=== RocketMQ 介绍
https://rocketmq.apache.org[RocketMQ] 是一款开源的分布式消息系统,基于高可用分布式集群技术,提供低延时的、高可靠的消息发布与订阅服务。同时,广泛应用于多个领域,包括异步通信解耦、企业解决方案、金融支付、电信、电子商务、快递物流、广告营销、社交、即时通信、移动应用、手游、视频、物联网、车联网等。
@@ -16,7 +16,7 @@ https://rocketmq.apache.org[RocketMQ] 是一款开源的分布式消息系统,
* 亿级消息堆积能力
### RocketMQ 基本使用
=== RocketMQ 基本使用
* 下载 RocketMQ
@@ -74,7 +74,7 @@ sh bin/mqshutdown broker
sh bin/mqshutdown namesrv
```
### Spring Cloud Stream 介绍
=== Spring Cloud Stream 介绍
Spring Cloud Stream 是一个用于构建基于消息的微服务应用框架。它基于 SpringBoot 来创建具有生产级别的单机 Spring 应用,并且使用 `Spring Integration` 与 Broker 进行连接。
@@ -115,7 +115,7 @@ messageChannel.send(MessageBuilder.withPayload("simple msg").build());
**Spring Cloud Stream 底层基于这段代码去做了各种抽象。**
### 如何使用 Spring Cloud Alibaba RocketMQ Binder ###
=== 如何使用 Spring Cloud Alibaba RocketMQ Binder ###
如果要在您的项目中引入 RocketMQ Binder需要引入如下 maven 依赖:
@@ -135,7 +135,7 @@ messageChannel.send(MessageBuilder.withPayload("simple msg").build());
</dependency>
```
### Spring Cloud Alibaba RocketMQ Binder 实现
=== Spring Cloud Alibaba RocketMQ Binder 实现
这是 Spring Cloud Stream RocketMQ Binder 的实现架构:
@@ -166,12 +166,12 @@ NOTE: 在使用 RocketMQ Binder 的同时也可以配置 rocketmq.** 用于触
MessageBuilder builder = MessageBuilder.withPayload(msg)
.setHeader(RocketMQHeaders.TAGS, "binder")
.setHeader(RocketMQHeaders.KEYS, "my-key")
.setHeader("DELAY", "1");
.setHeader(MessageConst.PROPERTY_DELAY_TIME_LEVEL, "1");
Message message = builder.build();
output().send(message);
```
### MessageSource 支持
=== MessageSource 支持
SCS RocketMQ Binder 支持 `MessageSource`,可以进行消息的拉取,例子如下:
@@ -225,9 +225,9 @@ public class MQApplication {
### 配置选项
=== 配置选项
#### RocketMQ Binder Properties
==== RocketMQ Binder Properties
spring.cloud.stream.rocketmq.binder.name-server::
RocketMQ NameServer 地址(老版本使用 namesrv-addr 配置项)。
@@ -251,7 +251,7 @@ spring.cloud.stream.rocketmq.binder.customized-trace-topic::
Default: `RMQ_SYS_TRACE_TOPIC`.
#### RocketMQ Consumer Properties
==== RocketMQ Consumer Properties
下面的这些配置是以 `spring.cloud.stream.rocketmq.bindings.<channelName>.consumer.` 为前缀的 RocketMQ Consumer 相关的配置。
@@ -287,7 +287,7 @@ suspendCurrentQueueTimeMillis::
+
默认值: `1000`.
#### RocketMQ Provider Properties
==== RocketMQ Provider Properties
下面的这些配置是以 `spring.cloud.stream.rocketmq.bindings.<channelName>.producer.` 为前缀的 RocketMQ Producer 相关的配置。
@@ -336,7 +336,7 @@ retryNextServer::
+
默认值: `false`.
### 阿里云 MQ 服务
=== 阿里云 MQ 服务
使用阿里云 MQ 服务需要配置 AccessKey、SecretKey 以及云上的 NameServer 地址。
@@ -351,4 +351,4 @@ spring.cloud.stream.rocketmq.binder.name-server=NameServerInMQ
NOTE: topic 和 group 请以 实例id% 为前缀进行配置。比如 topic 为 "test",需要配置成 "实例id%test"
.NameServer 的获取(配置中请去掉 http:// 前缀)
image::https://spring-cloud-alibaba.oss-cn-beijing.aliyuncs.com/MQ.png[]
image::https://spring-cloud-alibaba.oss-cn-beijing.aliyuncs.com/MQ.png[]

View File

@@ -1,6 +1,6 @@
== Spring Cloud Alibaba Sentinel
### Sentinel 介绍
=== Sentinel 介绍
随着微服务的流行,服务和服务之间的稳定性变得越来越重要。 https://github.com/alibaba/Sentinel[Sentinel] 以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。
@@ -11,11 +11,12 @@ https://github.com/alibaba/Sentinel[Sentinel] 具有以下特征:
* *广泛的开源生态* Sentinel 提供开箱即用的与其它开源框架/库的整合模块,例如与 Spring Cloud、Dubbo、gRPC 的整合。您只需要引入相应的依赖并进行简单的配置即可快速地接入 Sentinel。
* *完善的 SPI 扩展点* Sentinel 提供简单易用、完善的 SPI 扩展点。您可以通过实现扩展点,快速的定制逻辑。例如定制规则管理、适配数据源等。
### 如何使用 Sentinel
=== 如何使用 Sentinel
如果要在您的项目中引入 Sentinel使用 group ID 为 `com.alibaba.cloud` 和 artifact ID 为 `spring-cloud-starter-alibaba-sentinel` 的 starter。
```xml
[source,yaml]
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
@@ -75,7 +76,7 @@ public class TestController {
}
```
##### Sentinel 控制台
===== Sentinel 控制台
Sentinel 控制台提供一个轻量级的控制台,它提供机器发现、单机资源实时监控、集群资源汇总,以及规则管理的功能。您只需要对应用进行简单的配置,就可以使用这些功能。
@@ -86,7 +87,7 @@ image::https://github.com/alibaba/Sentinel/wiki/image/dashboard.png[]
开启该功能需要3个步骤
###### 获取控制台
====== 获取控制台
您可以从 https://github.com/alibaba/Sentinel/releases[release 页面] 下载最新版本的控制台 jar 包。
@@ -96,7 +97,7 @@ image::https://github.com/alibaba/Sentinel/wiki/image/dashboard.png[]
* 使用以下命令将代码打包成一个 fat jar: `mvn clean package`
###### 启动控制台
====== 启动控制台
Sentinel 控制台是一个标准的 SpringBoot 应用,以 SpringBoot 的方式运行 jar 包即可。
@@ -106,10 +107,9 @@ java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject
如若8080端口冲突可使用 `-Dserver.port=新端口` 进行设置。
#### 配置控制台信息
==== 配置控制台信息
.application.yml
[source,yaml]
----
spring:
cloud:
@@ -123,7 +123,7 @@ spring:
更多 Sentinel 控制台的使用及问题参考: https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0[Sentinel控制台]
### OpenFeign 支持
=== OpenFeign 支持
Sentinel 适配了 https://github.com/OpenFeign/feign[OpenFeign] 组件。如果想使用,除了引入 `sentinel-starter` 的依赖外还需要 2 个步骤:
@@ -141,7 +141,7 @@ Sentinel 适配了 https://github.com/OpenFeign/feign[OpenFeign] 组件。如果
```java
@FeignClient(name = "service-provider", fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class)
public interface EchoService {
@RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
@GetMapping(value = "/echo/{str}")
String echo(@PathVariable("str") String str);
}
@@ -164,7 +164,7 @@ NOTE: Feign 对应的接口中的资源名策略定义httpmethod:protocol://r
`EchoService` 接口中方法 `echo` 对应的资源名为 `GET:http://service-provider/echo/{str}`。
### RestTemplate 支持
=== RestTemplate 支持
Spring Cloud Alibaba Sentinel 支持对 `RestTemplate` 的服务调用使用 Sentinel 进行保护,在构造 `RestTemplate` bean的时候需要加上 `@SentinelRestTemplate` 注解。
@@ -206,7 +206,7 @@ Sentinel RestTemplate 限流的资源规则提供两种粒度:
NOTE: 以 `https://www.taobao.com/test` 这个 url 并使用 GET 方法为例。对应的资源名有两种粒度,分别是 `GET:https://www.taobao.com` 以及 `GET:https://www.taobao.com/test`
### 动态数据源支持
=== 动态数据源支持
`SentinelProperties` 内部提供了 `TreeMap` 类型的 `datasource` 属性用于配置数据源信息。
@@ -254,7 +254,7 @@ NOTE: 默认情况下xml 格式是不支持的。需要添加 `jackson-datafo
关于 Sentinel 动态数据源的实现原理,参考: https://github.com/alibaba/Sentinel/wiki/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%99%E6%89%A9%E5%B1%95[动态规则扩展]
### Zuul 支持
=== Zuul 支持
https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81[参考 Sentinel 网关限流]
@@ -277,7 +277,7 @@ https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81[
</dependency>
```
### Spring Cloud Gateway 支持
=== Spring Cloud Gateway 支持
https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81[参考 Sentinel 网关限流]
@@ -300,7 +300,7 @@ https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81[
</dependency>
```
### Sentinel 对外暴露的 Endpoint
=== Sentinel 对外暴露的 Endpoint
Sentinel 内部提供了一个 Endpoint, 对应的 endpoint id 为 `sentinel`。
@@ -404,7 +404,7 @@ Endpoint 暴露的 json 中包含了多种属性:
}
----
### 关于 Sentinel Starter 更多的配置项信息
=== 关于 Sentinel Starter 更多的配置项信息
下表显示当应用的 `ApplicationContext` 中存在对应的Bean的类型时会进行自动化设置

View File

@@ -0,0 +1,165 @@
== 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] 。目前支持的服务发现组件:
* Nacos
* Consul
=== 术语
==== 异构微服务
非Spring Cloud应用统称异构微服务。比如你的遗留项目或者非JVM应用。
==== ``完美整合''的三层含义
* 享受服务发现的优势
* 有负载均衡
* 有断路器
=== Why or Why not?
==== 为什么要编写Alibaba Sidecar
原因有两点:
* 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方案颇有点屠龙刀杀黄鳝的意思。
=== 原理
* Alibaba
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"}` 的字符串即可)。
=== 使用示例
* 如使用Nacos作为服务发现组件详见`spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-nacos-example`
* 如使用Consul作为服务发现组件详见`spring-cloud-alibaba-examples/spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-nacos-example`
==== 示例代码以Nacos服务发现为例
* 加依赖:
+
[source,xml]
----
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sidecar</artifactId>
</dependency>
----
* 写配置:
+
[source,yaml]
----
server:
port: 8070
spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848
gateway:
discovery:
locator:
enabled: true
application:
name: node-service
sidecar:
# 异构微服务的IP
ip: 127.0.0.1
# 异构微服务的端口
port: 8060
# 异构微服务的健康检查URL
health-check-url: http://localhost:8060/health.json
management:
endpoint:
health:
show-details: always
----
+
配置比较简单就是把Alibaba Sidecar注册到Nacos上然后添加了几行Alibaba Sidecar的配置。
==== 异构微服务
我准备了一个NodeJS编写的简单微服务。
[source,javascript]
----
var http = require('http');
var url = require("url");
var path = require('path');
// 创建server
var server = http.createServer(function(req, res) {
// 获得请求的路径
var pathname = url.parse(req.url).pathname;
res.writeHead(200, { 'Content-Type' : 'application/json; charset=utf-8' });
// 访问http://localhost:8060/,将会返回{"index":"欢迎来到首页"}
if (pathname === '/') {
res.end(JSON.stringify({ "index" : "欢迎来到首页" }));
}
// 访问http://localhost:8060/health将会返回{"status":"UP"}
else if (pathname === '/health.json') {
res.end(JSON.stringify({ "status" : "UP" }));
}
// 其他情况返回404
else {
res.end("404");
}
});
// 创建监听,并打印日志
server.listen(8060, function() {
console.log('listening on localhost:8060');
});
----
==== 测试
===== 测试1Spring Cloud微服务完美调用异构微服务
为你的Spring Cloud微服务整合Ribbon然后构建 `http://node-service/\\**`,就可以请求到异构微服务的 `/**` 了。
示例:
Ribbon请求 `http://node-service/` 会请求到 `http://localhost:8060/`,以此类推。
至于断路器正常为你的Spring Cloud微服务整合Sentinel或者Hystirx、Resilience4J即可 。
===== 测试2异构微服务完美调用Spring Cloud微服务
由于Alibaba Sidecar基于Spring Cloud Gateway而网关自带转发能力。
示例:
如果你有一个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所以也带有了断路器。
=== Alibaba Sidecar优缺点分析
Alibaba Sidecar的设计和Sidecar基本一致优缺点和Sidecar的优缺点也是一样的。
优点:
* 接入简单几行代码就可以将异构微服务整合到Spring Cloud生态
* 不侵入原代码
缺点:
* 每接入一个异构微服务实例都需要额外部署一个Alibaba Sidecar实例增加了部署成本虽然这个成本在Kubernetes环境中几乎可以忽略不计只需将Alibaba Sidecar实例和异构微服务作为一个Pod部署即可
* 异构微服务调用Spring Cloud微服务时本质是把Alibaba Sidecar当网关在使用经过了一层转发性能有一定下降。

View File

@@ -31,3 +31,6 @@ include::schedulerx.adoc[]
include::sms.adoc[]
include::sidecar.adoc[]

View File

@@ -93,3 +93,4 @@ Access-key and secret-key are the AK/SK of your Alibaba Cloud account. Register
Namespace is a concept in EDAS, which is used to isolate environments, such as testing environment and production environment. To find your namespace, click to https://common-buy.aliyun.com/?spm=5176.11451019.0.0.6f5965c0Uq5tue&commodityCode=edaspostpay#/buy[Sign up for EDAS] first. You will not be charged under the pay-as-you-go mode. Then log on to the https://edas.console.aliyun.com/#/namespaces?regionNo=cn-hangzhou[EDAS Console] and you will be able to see your namespace, for example cn-hangzhou.
NOTE: EDAS provides application hosting service and will fill in all configurations automatically for the hosted applications.

View File

@@ -0,0 +1,73 @@
=== Circuit Breaker: Spring Cloud Circuit Breaker With Sentinel & Configuring Sentinel Circuit Breakers
==== Default Configuration
To provide a default configuration for all of your circuit breakers create a `Customizer` bean that is passed a
`SentinelCircuitBreakerFactory` or `ReactiveSentinelCircuitBreakerFactory`.
The `configureDefault` method can be used to provide a default configuration.
====
[source,java]
----
@Bean
public Customizer<SentinelCircuitBreakerFactory> defaultCustomizer() {
return factory -> factory.configureDefault(id -> new SentinelConfigBuilder(id)
.build());
}
----
====
You can choose to provide default circuit breaking rules via `SentinelConfigBuilder#rules(rules)`.
You can also choose to load circuit breaking rules later elsewhere using
`DegradeRuleManager.loadRules(rules)` API of Sentinel, or via Sentinel dashboard.
===== Reactive Example
====
[source,java]
----
@Bean
public Customizer<ReactiveSentinelCircuitBreakerFactory> defaultCustomizer() {
return factory -> factory.configureDefault(id -> new SentinelConfigBuilder(id)
.build());
}
----
====
==== Specific Circuit Breaker Configuration
Similarly to providing a default configuration, you can create a `Customizer` bean this is passed a
`SentinelCircuitBreakerFactory`.
====
[source,java]
----
@Bean
public Customizer<SentinelCircuitBreakerFactory> slowCustomizer() {
String slowId = "slow";
List<DegradeRule> rules = Collections.singletonList(
new DegradeRule(slowId).setGrade(RuleConstant.DEGRADE_GRADE_RT)
.setCount(100)
.setTimeWindow(10)
);
return factory -> factory.configure(builder -> builder.rules(rules), slowId);
}
----
====
===== Reactive Example
====
[source,java]
----
@Bean
public Customizer<ReactiveSentinelCircuitBreakerFactory> customizer() {
List<DegradeRule> rules = Collections.singletonList(
new DegradeRule().setGrade(RuleConstant.DEGRADE_GRADE_RT)
.setCount(100)
.setTimeWindow(10)
);
return factory -> factory.configure(builder -> builder.rules(rules), "foo", "bar");
}
----
====

View File

@@ -17,3 +17,4 @@ If youre a Maven Central user, add our BOM to your pom.xml <dependencyManagem
```
In the following sections, it will be assumed you are using the Spring Cloud Alibaba BOM and the dependency snippets will not contain versions.

View File

@@ -1,4 +1,4 @@
## Introduction
== 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.

View File

@@ -41,10 +41,10 @@ For more Nacos Server versions, you can download the latest version from https:/
The following sample illustrates how to register a service to Nacos.
* Configuration of pom.xml The following is a complete example of pom.xml:
* Configuration of pom.xml The following is a complete example of pom.xml
.pom.xml
[source, xml]
[source,xml]
----
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

View File

@@ -154,4 +154,4 @@ spring.cloud.alicloud.oss.config.max-connections=1000
For more configurations, refer to the table at the bottom of https://help.aliyun.com/document_detail/32010.html[OSSClient Configurations].
NOTE: In most cases, you need to connect the parameter names with “-” for the parameters in the table of https://help.aliyun.com/document_detail/32010.html[OSSClient Configurations] with “-”, and all letters should be in lowercase. For example, ConnectionTimeout should be changed to connection-timeout.
NOTE: In most cases, you need to connect the parameter names with “-” for the parameters in the table of https://help.aliyun.com/document_detail/32010.html[OSSClient Configurations] with “-”, and all letters should be in lowercase. For example, ConnectionTimeout should be changed to connection-timeout.

View File

@@ -1,6 +1,6 @@
== Spring Cloud Alibaba RocketMQ Binder
### Introduction of RocketMQ
=== Introduction of RocketMQ
https://rocketmq.apache.org[RocketMQ] is an open-source distributed message system. It is based on highly available distributed cluster technologies and provides message publishing and subscription service with low latency and high stability. RocketMQ is widely used in a variety of industries, such as decoupling of asynchronous communication, enterprise sulotions, financial settlements, telecommunication, e-commerce, logistics, marketing, social media, instant messaging, mobile applications, mobile games, vedios, IoT, and Internet of Vehicles.
@@ -16,7 +16,7 @@ It has the following features:
* Billion-level message accumulation capability
### RocketMQ Usages
=== RocketMQ Usages
* Download RocketMQ
@@ -74,7 +74,7 @@ sh bin/mqshutdown broker
sh bin/mqshutdown namesrv
```
### Introduction of Spring Cloud Stream
=== Introduction of Spring Cloud Stream
Spring Cloud Stream is a microservice framework used to build architectures based on messages. It helps you to create production-ready single-server Spring applications based on SpringBoot, and connects with Broker using `Spring Integration`.
@@ -114,7 +114,7 @@ All the message types in this code are provided by the `spring-messaging`module.
**The lower layer of Spring Cloud Stream also implements various code abstractions based on the previous code.**
### How to use Spring Cloud Alibaba RocketMQ Binder ###
=== How to use Spring Cloud Alibaba RocketMQ Binder
For using the Spring Cloud Alibaba RocketMQ Binder, you just need to add it to your Spring Cloud Stream application, using the following Maven coordinates:
@@ -134,7 +134,7 @@ Alternatively, you can also use the Spring Cloud Stream RocketMQ Starter:
</dependency>
```
### How Spring Cloud Alibaba RocketMQ Binder Works
=== How Spring Cloud Alibaba RocketMQ Binder Works
This is the implementation architecture of Spring Cloud Stream RocketMQ Binder:
@@ -165,12 +165,12 @@ For example, `TAGS`, `DELAY`, `TRANSACTIONAL_ARG`, `KEYS`, `WAIT_STORE_MSG_OK`,
MessageBuilder builder = MessageBuilder.withPayload(msg)
.setHeader(RocketMQHeaders.TAGS, "binder")
.setHeader(RocketMQHeaders.KEYS, "my-key")
.setHeader("DELAY", "1");
.setHeader(MessageConst.PROPERTY_DELAY_TIME_LEVEL, "1");
Message message = builder.build();
output().send(message);
```
### Support MessageSource
=== Support MessageSource
SCS RocketMQ Binder support `MessageSource`which can receive messages by pull mode
@@ -222,9 +222,9 @@ public class MQApplication {
}
```
### Configuration Options
=== Configuration Options
#### RocketMQ Binder Properties
==== RocketMQ Binder Properties
spring.cloud.stream.rocketmq.binder.name-server::
The name server of RocketMQ Server(Older versions use the namesrv-addr configuration item).
@@ -248,7 +248,7 @@ The trace topic for message trace.
Default: `RMQ_SYS_TRACE_TOPIC`.
#### RocketMQ Consumer Properties
==== RocketMQ Consumer Properties
The following properties are available for RocketMQ producers only and must be prefixed with `spring.cloud.stream.rocketmq.bindings.<channelName>.consumer.`.
@@ -284,7 +284,7 @@ Time interval of message consume retry for orderly consume.
+
Default: `1000`.
#### RocketMQ Provider Properties
==== RocketMQ Provider Properties
The following properties are available for RocketMQ producers only and must be prefixed with `spring.cloud.stream.rocketmq.bindings.<channelName>.producer.`.

View File

@@ -111,4 +111,4 @@ NOTE: Group-id must be created within a namespace.
Access-key and secret-key are the AK/SK of your Alibaba Cloud account. If you deploy you applications on EDAS, then you do not need to fill in this information. Otherwise please go to https://usercenter.console.aliyun.com/#/manage/ak[Security Information] to get your AccessKeys.
Domain-name is not mandatory. You can refer to https://help.aliyun.com/document_detail/35359.html[SchedulerX Documentation] for details.
Domain-name is not mandatory. You can refer to https://help.aliyun.com/document_detail/35359.html[SchedulerX Documentation] for details.

View File

@@ -1,6 +1,6 @@
== Spring Cloud Alibaba Sentinel
### Introduction of Sentinel
=== Introduction of Sentinel
As microservices become popular, the stability of service calls is becoming increasingly important. https://github.com/alibaba/Sentinel[Sentinel] takes "flow" as the breakthrough point, and works on multiple fields including flow control, circuit breaking and load protection to protect service reliability.
@@ -12,7 +12,7 @@ https://github.com/alibaba/Sentinel[Sentinel] has the following features:
* *Extensive Open-Source Ecosystem* Sentinel provides out-of-box modules that can be easily integrated with other open-source frameworks/libraries, such as Spring Cloud, Dubbo, and gRPC. To use Sentinel, you only need to introduce the related dependency and make a few simple configurations.
* *Sound SPI Extensions* Sentinel provides easy-to-use and sound SPI extension interfaces. You can customize logics with the SPI extensions quickly, for example, you can define your own rule management, or adapt to specific data sources.
### How to Use Sentinel
=== How to Use Sentinel
If you want to use Sentinel in your project, please use the starter with the group ID as `com.alibaba.cloud` and the artifact ID as `spring-cloud-starter-alibaba-sentinel`.
@@ -76,7 +76,7 @@ public class TestController {
}
```
##### Sentinel Dashboard
===== Sentinel Dashboard
Sentinel dashboard is a lightweight console that provides functions such as machine discovery, single-server resource monitoring, overview of cluster resource data, as well as rule management. To use these features, you only need to complete a few steps.
@@ -87,7 +87,7 @@ image::https://github.com/alibaba/Sentinel/wiki/image/dashboard.png[]
To use the Sentinel dashboard, simply complete the following 3 steps.
###### Get the Dashboard
====== Get the Dashboard
You can download the latest dashboard JAR file from the https://github.com/alibaba/Sentinel/releases[Release Page].
@@ -97,7 +97,7 @@ You can also get the latest source code to build your own Sentinel dashboard
* Run the following command to package the code into a FatJar: `mvn clean package`
###### Start the Dashboard
====== Start the Dashboard
Sentinel dashboard is a standard SpringBoot application, and you can run the JAR file in the Spring Boot mode.
@@ -107,7 +107,7 @@ java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject
If there is conflict with the 8080 port, you can use `-Dserver.port=new port` to define a new port.
#### Configure the Dashboard
==== Configure the Dashboard
.application.yml
[source,yaml]
@@ -124,7 +124,7 @@ The port number specified in `spring.cloud.sentinel.transport.port` will start a
For more information about Sentinel dashboard, please refer to https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0[Sentinel Dashboard].
### OpenFeign Support
=== OpenFeign Support
Sentinel is compatible with the https://github.com/OpenFeign/feign[OpenFeign] component. To use it, in addition to introducing the `sentinel-starter` dependency, complete the following 2 steps:
@@ -142,7 +142,7 @@ This is a simple usage of `FeignClient`:
```java
@FeignClient(name = "service-provider", fallback = EchoServiceFallback.class, configuration = FeignConfiguration.class)
public interface EchoService {
@RequestMapping(value = "/echo/{str}", method = RequestMethod.GET)
@GetMapping(value = "/echo/{str}")
String echo(@PathVariable("str") String str);
}
@@ -165,7 +165,7 @@ NOTE: The resource name policy in the corresponding interface of Feign ishttp
The corresponding resource name of the `echo` method in the `EchoService` interface is `GET:http://service-provider/echo/{str}`.
### RestTemplate Support
=== RestTemplate Support
Spring Cloud Alibaba Sentinel supports the protection of `RestTemplate` service calls using Sentinel. To do this, you need to add the `@SentinelRestTemplate` annotation when constructing the `RestTemplate` bean.
@@ -209,7 +209,7 @@ Sentinel RestTemplate provides two granularities for resource rate limiting:
NOTE: Take Http GET `https://www.taobao.com/test` as an example. The corresponding resource names have two levels of granularities, `GET:https://www.taobao.com` and `GET:https://www.taobao.com/test`.
### Dynamic Data Source Support
=== Dynamic Data Source Support
`SentinelProperties` provide `datasource` attribute to configure datasource.
@@ -255,9 +255,9 @@ NOTE: XML format is not supported by default. To make it effective, you need to
To learn more about how dynamic data sources work in Sentinel, refer to https://github.com/alibaba/Sentinel/wiki/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%99%E6%89%A9%E5%B1%95[Dynamic Rule Extension].
### Support Zuul
=== Support Zuul
https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81[参考 Sentinel 网关限流]
Refer https://github.com/alibaba/Sentinel/wiki/API-Gateway-Flow-Control[API Gateway Flow Control]
If you want to use Sentinel Starter with Zuul, you need to add the `spring-cloud-alibaba-sentinel-gateway` dependency, and you need to add the `spring-cloud-starter-netflix-zuul` dependency to let Zuul AutoConfiguration class in the gateway module takes effect:
@@ -278,9 +278,9 @@ If you want to use Sentinel Starter with Zuul, you need to add the `spring-cloud
</dependency>
```
### Support Spring Cloud Gateway
=== Support Spring Cloud Gateway
https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81[参考 Sentinel 网关限流]
Refer https://github.com/alibaba/Sentinel/wiki/API-Gateway-Flow-Control[API Gateway Flow Control]
If you want to use Sentinel Starter with Spring Cloud Gateway, you need to add the `spring-cloud-alibaba-sentinel-gateway` dependency and add the `spring-cloud-starter-gateway` dependency to let Spring Cloud Gateway AutoConfiguration class in the module takes effect:
@@ -301,7 +301,9 @@ If you want to use Sentinel Starter with Spring Cloud Gateway, you need to add t
</dependency>
```
### Sentinel Endpoint
include::circuitbreaker-sentinel.adoc[]
=== Sentinel Endpoint
Sentinel provides an Endpoint internally with a corresponding endpoint id of `sentinel`.
@@ -404,7 +406,7 @@ The followings shows how a service instance accesses the Endpoint:
}
----
### Configuration
=== Configuration
The following table shows that when there are corresponding bean types in `ApplicationContext`, some actions will be taken:
@@ -447,4 +449,4 @@ The following table shows all the configurations of Spring Cloud Alibaba Sentine
|===
NOTE: These configurations will only take effect in servlet environment. RestTemplate and Feign will not take effect for these configurations.
NOTE: These configurations will only take effect in servlet environment. RestTemplate and Feign will not take effect for these configurations.

View File

@@ -207,4 +207,4 @@ public class SmsUpMessageListener
}
----
More message body format for Message can be https://help.aliyun.com/document_detail/55496.html?spm=a2c4g.11186623.6.570.7f792c78rOiWXO[reference here].
More message body format for Message can be https://help.aliyun.com/document_detail/55496.html?spm=a2c4g.11186623.6.570.7f792c78rOiWXO[reference here].