diff --git a/pom.xml b/pom.xml
index 4f3a43607..a2a7aa0fd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -89,6 +89,7 @@
spring-cloud-alibaba-sentinel-datasource
spring-cloud-alibaba-nacos-config
spring-cloud-alibaba-nacos-discovery
+ spring-cloud-stream-binder-rocketmq
spring-cloud-alibaba-nacos-config-server
spring-cloud-alicloud-context
spring-cloud-alibaba-examples
diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml
index 5d082bf76..042507651 100644
--- a/spring-cloud-alibaba-dependencies/pom.xml
+++ b/spring-cloud-alibaba-dependencies/pom.xml
@@ -9,6 +9,7 @@
2.0.4.RELEASE
+
spring-cloud-alibaba-dependencies
0.2.1.BUILD-SNAPSHOT
pom
@@ -184,6 +185,11 @@
spring-cloud-alicloud-context
${project.version}
+
+ org.springframework.cloud
+ spring-cloud-stream-binder-rocketmq
+ ${project.version}
+
@@ -220,11 +226,24 @@
spring-cloud-starter-alicloud-acm
${project.version}
-
+
+ org.springframework.cloud
+ spring-cloud-starter-stream-rocketmq
+ ${project.version}
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bus-rocketmq
+ ${project.version}
+
+
+
+
spring
diff --git a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/sentinel.adoc b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/sentinel.adoc
index 59eaa589c..260c3df3c 100644
--- a/spring-cloud-alibaba-docs/src/main/asciidoc-zh/sentinel.adoc
+++ b/spring-cloud-alibaba-docs/src/main/asciidoc-zh/sentinel.adoc
@@ -1 +1,250 @@
== Spring Cloud Alibaba Sentinel
+
+### Sentinel介绍
+
+随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。
+
+Sentinel 具有以下特征:
+
+
+* *丰富的应用场景*:Sentinel 承接了阿里巴巴近 10 年的双十一大促流量的核心场景,例如秒杀(即突发流量控制在系统容量可以承受的范围)、消息削峰填谷、实时熔断下游不可用应用等。
+* *完备的实时监控*:Sentinel 同时提供实时的监控功能。您可以在控制台中看到接入应用的单台机器秒级数据,甚至 500 台以下规模的集群的汇总运行情况。
+* *广泛的开源生态*:Sentinel 提供开箱即用的与其它开源框架/库的整合模块,例如与 Spring Cloud、Dubbo、gRPC 的整合。您只需要引入相应的依赖并进行简单的配置即可快速地接入 Sentinel。
+* *完善的 SPI 扩展点*:Sentinel 提供简单易用、完善的 SPI 扩展点。您可以通过实现扩展点,快速的定制逻辑。例如定制规则管理、适配数据源等。
+
+### 如何使用Sentinel
+
+如果要在您的项目中引入Sentinel,使用group ID为 `org.springframework.cloud` 和artifact ID为 `spring-cloud-starter-alibaba-sentinel` 的starter。
+
+```xml
+
+ org.springframework.cloud
+ spring-cloud-starter-alibaba-sentinel
+
+```
+
+下面这个例子就是一个最简单的使用Sentinel的例子:
+
+```java
+@SpringBootApplication
+public class Application {
+
+ public static void main(String[] args) {
+ SpringApplication.run(ServiceApplication.class, args);
+ }
+
+}
+
+@RestController
+public class TestController {
+
+ @GetMapping(value = "/hello")
+ @SentinelResource("hello")
+ public String hello() {
+ return "Hello Sentinel";
+ }
+
+}
+```
+
+@SentinelResource注解用来标识资源是否被限流、降级。上述例子上该注解的属性'hello'表示资源名。
+
+@SentinelResource还提供了其它额外的属性如 `blockHandler`,`blockHandlerClass`,`fallback` 用于表示限流或降级的操作,更多内容可以参考 https://github.com/alibaba/Sentinel/wiki/%E6%B3%A8%E8%A7%A3%E6%94%AF%E6%8C%81[Sentinel注解支持]。
+
+##### Sentinel 控制台
+
+Sentinel 控制台提供一个轻量级的控制台,它提供机器发现、单机资源实时监控、集群资源汇总,以及规则管理的功能。您只需要对应用进行简单的配置,就可以使用这些功能。
+
+*注意*: 集群资源汇总仅支持 500 台以下的应用集群,有大概 1 - 2 秒的延时。
+
+.Sentinel Dashboard
+image::https://github.com/alibaba/Sentinel/wiki/image/dashboard.png[]
+
+开启该功能需要3个步骤:
+
+###### 获取控制台
+
+您可以从 https://github.com/alibaba/Sentinel/releases[release 页面] 下载最新版本的控制台 jar 包。
+
+您也可以从最新版本的源码自行构建 Sentinel 控制台:
+
+* 下载 https://github.com/alibaba/Sentinel/tree/master/sentinel-dashboard[控制台] 工程
+* 使用以下命令将代码打包成一个 fat jar: `mvn clean package`
+
+
+###### 启动控制台
+
+Sentinel 控制台是一个标准的SpringBoot应用,以SpringBoot的方式运行jar包即可。
+
+```shell
+java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar
+```
+
+如若8080端口冲突,可使用 `-Dserver.port=新端口` 进行设置。
+
+#### 配置控制台信息
+
+.application.yml
+----
+spring:
+ cloud:
+ sentinel:
+ transport:
+ port: 8719
+ dashboard: localhost:8080
+----
+
+这里的 `spring.cloud.sentinel.transport.port` 端口配置会在应用对应的机器上启动一个Http Server,该Serve会与Sentinel控制台做交互。比如Sentinel控制台添加了1个限流规则,会把规则数据push给这个Http Server接受,Http Server再将规则注册到Sentinel中。
+
+更多Sentinel控制台的使用及问题参考: https://github.com/alibaba/Sentinel/wiki/%E6%8E%A7%E5%88%B6%E5%8F%B0[Sentinel控制台]
+
+### Feign支持
+
+DOING
+
+### RestTemplate支持
+
+Spring Cloud Alibaba Sentinel支持对 `RestTemplate` 的服务调用使用Sentinel进行保护,在构造 `RestTemplate` bean的时候需要加上 `@SentinelProtect` 注解。
+
+```java
+@Bean
+@SentinelProtect(blockHandler = "handleException", blockHandlerClass = ExceptionUtil.class)
+public RestTemplate restTemplate() {
+ return new RestTemplate();
+}
+```
+
+`@SentinelProtect` 注解的参数跟 `@SentinelResource` 一致,使用方式也一致。
+
+限流的资源规则提供两种粒度:
+
+* `schema://host:port/path`:协议、主机、端口和路径
+
+* `schema://host:port`:协议、主机和端口
+
+NOTE: 以 `https://www.taobao.com/test` 这个url为例。对应的资源名有两种粒度,分别是 `https://www.taobao.com:80` 以及 `https://www.taobao.com:80/test`
+
+
+### 动态数据源支持
+
+*在版本 0.2.0.RELEASE 或 0.1.0.RELEASE 之前*,要在Spring Cloud Alibaba Sentinel下使用动态数据源,需要3个步骤:
+
+* 配置文件中定义数据源信息。比如使用文件:
+
+.application.properties
+----
+spring.cloud.sentinel.datasource.type=file
+spring.cloud.sentinel.datasource.recommendRefreshMs=3000
+spring.cloud.sentinel.datasource.bufSize=4056196
+spring.cloud.sentinel.datasource.charset=utf-8
+spring.cloud.sentinel.datasource.converter=flowConverter
+spring.cloud.sentinel.datasource.file=/Users/you/yourrule.json
+----
+
+* 创建一个Converter类实现 `com.alibaba.csp.sentinel.datasource.Converter` 接口,并且需要在 `ApplicationContext` 中有该类的一个Bean
+
+```java
+@Component("flowConverter")
+public class JsonFlowRuleListParser implements Converter> {
+ @Override
+ public List convert(String source) {
+ return JSON.parseObject(source, new TypeReference>() {
+ });
+ }
+}
+```
+
+这个Converter的bean name需要跟 `application.properties` 配置文件中的converter配置一致
+
+* 在任意一个 Spring Bean 中定义一个被 `@SentinelDataSource` 注解修饰的 `ReadableDataSource` 属性
+
+```java
+@SentinelDataSource("spring.cloud.sentinel.datasource")
+private ReadableDataSource dataSource;
+```
+
+`@SentinelDataSource` 注解的value属性表示数据源在 `application.properties` 配置文件中前缀。 该在例子中,前缀为 `spring.cloud.sentinel.datasource` 。
+
+如果 `ApplicationContext` 中存在超过1个 `ReadableDataSource` bean,那么不会加载这些 `ReadableDataSource` 中的任意一个。 只有在 `ApplicationContext` 存在一个 `ReadableDataSource` 的情况下才会生效。
+
+如果数据库生效并且规则成功加载,控制台会打印类似如下信息:
+
+```
+[Sentinel Starter] load 3 flow rules
+```
+
+*在版本 0.2.0.RELEASE 或 0.1.0.RELEASE 之后*,要在Spring Cloud Alibaba Sentinel下使用动态数据源,只需要1个步骤:
+
+* 直接在 `application.properties` 配置文件中配置数据源信息即可
+
+比如配置了4个数据源:
+
+```
+spring.cloud.sentinel.datasource.ds1.file.file=classpath: degraderule.json
+
+spring.cloud.sentinel.datasource.ds2.nacos.server-addr=localhost:8848
+spring.cloud.sentinel.datasource.ds2.nacos.dataId=sentinel
+spring.cloud.sentinel.datasource.ds2.nacos.groupId=DEFAULT_GROUP
+spring.cloud.sentinel.datasource.ds2.nacos.data-type=json
+
+spring.cloud.sentinel.datasource.ds3.zk.path = /Sentinel-Demo/SYSTEM-CODE-DEMO-FLOW
+spring.cloud.sentinel.datasource.ds3.zk.server-addr = localhost:2181
+
+spring.cloud.sentinel.datasource.ds4.apollo.namespace-name = application
+spring.cloud.sentinel.datasource.ds4.apollo.flow-rules-key = sentinel
+spring.cloud.sentinel.datasource.ds4.apollo.default-flow-rule-value = test
+
+```
+
+这样配置方式参考了Spring Cloud Stream Binder的配置,内部使用了 `TreeMap` 进行存储,comparator为 `String.CASE_INSENSITIVE_ORDER` 。
+
+NOTE: d1, ds2, ds3, ds4 是 `ReadableDataSource` 的名字,可随意编写。后面的 `file` ,`zk` ,`nacos` , `apollo` 就是对应具体的数据源。 它们后面的配置就是这些数据源各自的配置。
+
+每种数据源都有两个共同的配置项: `data-type` 和 `converter-class` 。
+
+`data-type` 配置项表示 `Converter`,Spring Cloud Alibaba Sentinel默认提供两种内置的值,分别是 `json` 和 `xml` (不填默认是json)。 如果不想使用内置的 `json` 或 `xml` 这两种 `Converter`,可以填写 `custom` 表示自定义 `Converter`,然后再配置 `converter-class` 配置项,该配置项需要写类的全路径名。
+
+这两种内置的 `Converter` 只支持解析 json数组 或 xml数组。内部解析的时候会自动判断每个json对象或xml对象属于哪4种Sentinel规则(`FlowRule`,`DegradeRule`,`SystemRule`,`AuthorityRule`)。
+
+比如10个规则数组里解析出5个限流规则和5个降级规则。 这种情况下该数据源不会注册,日志里页会进行警告。
+
+如果10个规则里有9个限流规则,1个解析报错了。这种情况下日志会警告有个规则格式错误,另外9个限流规则会注册上去。
+
+这里json或xml解析用的是 `jackson`。`ObjectMapper` 或 `XmlMapper` 使用默认的配置,遇到不认识的字段会解析报错。 因为不这样做的话限流 json 也会解析成 系统规则(系统规则所有的配置都有默认值),所以需要这样严格解析。
+
+当然还有一种情况是json对象或xml对象可能会匹配上所有4种规则(比如json对象里只配了 `resource` 字段,那么会匹配上4种规则),这种情况下日志里会警告,并且过滤掉这个对象。
+
+用户使用这种配置的时候只需要填写正确的json或xml就行,有任何不合理的信息都会在日志里打印出来。
+
+NOTE: 默认情况下,xml格式是不支持的。需要添加 `jackson-dataformat-xml` 依赖后才会自动生效。
+
+关于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[动态规则扩展]
+
+### Endpoint支持
+
+在使用Endpoint特性之前需要在 Maven 中添加 `spring-boot-starter-actuator` 依赖,并在配置中允许 Endpoints 的访问。
+
+* Spring Boot 1.x 中添加配置 `management.security.enabled=false`。暴露的endpoint路径为 `/sentinel`
+* Spring Boot 2.x 中添加配置 `management.endpoints.web.exposure.include=*`。暴露的endpoint路径为 `/actuator/sentinel`
+
+### More
+
+下表显示 Spring Cloud Alibaba Sentinel 的所有配置信息:
+
+:frame: topbot
+[width="60%",options="header"]
+|====
+^|配置项 ^|含义 ^|默认值
+|`spring.cloud.sentinel.enabled`|Sentinel自动化配置是否生效|true
+|`spring.cloud.sentinel.eager`|取消Sentinel控制台懒加载|false
+|`spring.cloud.sentinel.charset`|metric文件字符集|UTF-8
+|`spring.cloud.sentinel.transport.port`|应用与Sentinel控制台交互的端口,应用本地会起一个该端口占用的HttpServer|8721
+|`spring.cloud.sentinel.transport.dashboard`|Sentinel 控制台地址|
+|`spring.cloud.sentinel.transport.heartbeatIntervalMs`|应用与Sentinel控制台的心跳间隔时间|
+|`spring.cloud.sentinel.filter.order`|Servlet Filter的加载顺序。Starter内部会构造这个filter|Integer.MIN_VALUE
+|`spring.cloud.sentinel.filter.spring.url-patterns`|数据类型是数组。表示Servlet Filter的url pattern集合|/*
+|`spring.cloud.sentinel.metric.fileSingleSize`|Sentinel metric 单个文件的大小|
+|`spring.cloud.sentinel.metric.fileTotalCount`|Sentinel metric 总文件数量|
+|`spring.cloud.sentinel.servlet.blockPage`| 自定义的跳转 URL,当请求被限流时会自动跳转至设定好的 URL |
+|`spring.cloud.sentinel.flow.coldFactor`| https://github.com/alibaba/Sentinel/wiki/%E9%99%90%E6%B5%81---%E5%86%B7%E5%90%AF%E5%8A%A8[冷启动因子] |3
+|====
diff --git a/spring-cloud-alibaba-examples/pom.xml b/spring-cloud-alibaba-examples/pom.xml
index acdcb6049..7d6b3b263 100644
--- a/spring-cloud-alibaba-examples/pom.xml
+++ b/spring-cloud-alibaba-examples/pom.xml
@@ -6,6 +6,7 @@
org.springframework.cloud
spring-cloud-alibaba
0.2.1.BUILD-SNAPSHOT
+ ../pom.xml
4.0.0
@@ -27,6 +28,8 @@
ans-example/ans-consumer-ribbon-example
ans-example/ans-provider-example
acm-example/acm-local-example
+ rocketmq-example
+ spring-cloud-bus-rocketmq-example
diff --git a/spring-cloud-alibaba-examples/rocketmq-example/pom.xml b/spring-cloud-alibaba-examples/rocketmq-example/pom.xml
new file mode 100644
index 000000000..bec837c36
--- /dev/null
+++ b/spring-cloud-alibaba-examples/rocketmq-example/pom.xml
@@ -0,0 +1,53 @@
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-alibaba-examples
+ 0.2.1.BUILD-SNAPSHOT
+ ../pom.xml
+
+ 4.0.0
+
+
+ rocketmq-example
+ jar
+ Example demonstrating how to use rocketmq
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-stream-rocketmq
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ ${maven-deploy-plugin.version}
+
+ true
+
+
+
+
+
+
diff --git a/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Foo.java b/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Foo.java
new file mode 100644
index 000000000..652400a2a
--- /dev/null
+++ b/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/Foo.java
@@ -0,0 +1,39 @@
+package org.springframework.cloud.alibaba.cloud.examples;
+
+/**
+ * @author Jim
+ */
+public class Foo {
+
+ private int id;
+ private String tag;
+
+ public Foo() {
+ }
+
+ public Foo(int id, String tag) {
+ this.id = id;
+ this.tag = tag;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ @Override
+ public String toString() {
+ return "Foo{" + "id=" + id + ", tag='" + tag + '\'' + '}';
+ }
+}
diff --git a/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ReceiveService.java b/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ReceiveService.java
new file mode 100644
index 000000000..f251902d9
--- /dev/null
+++ b/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ReceiveService.java
@@ -0,0 +1,33 @@
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.springframework.cloud.stream.annotation.StreamListener;
+import org.springframework.messaging.handler.annotation.Payload;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author Jim
+ */
+@Service
+public class ReceiveService {
+
+ @StreamListener("input1")
+ public void receiveInput1(String receiveMsg) {
+ System.out.println("input1 receive: " + receiveMsg);
+ }
+
+ @StreamListener("input2")
+ public void receiveInput2(String receiveMsg) {
+ System.out.println("input2 receive: " + receiveMsg);
+ }
+
+ @StreamListener("input3")
+ public void receiveInput3(@Payload Foo foo) {
+ System.out.println("input3 receive: " + foo);
+ }
+
+ @StreamListener("input1")
+ public void receiveInput1Again(String receiveMsg) {
+ System.out.println("input1 receive again: " + receiveMsg);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/RocketMQApplication.java b/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/RocketMQApplication.java
new file mode 100644
index 000000000..2d4deda68
--- /dev/null
+++ b/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/RocketMQApplication.java
@@ -0,0 +1,65 @@
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.alibaba.cloud.examples.RocketMQApplication.MySink;
+import org.springframework.cloud.stream.annotation.EnableBinding;
+import org.springframework.cloud.stream.annotation.Input;
+import org.springframework.cloud.stream.messaging.Source;
+import org.springframework.context.annotation.Bean;
+import org.springframework.messaging.SubscribableChannel;
+
+/**
+ * @author Jim
+ */
+@SpringBootApplication
+@EnableBinding({ Source.class, MySink.class })
+public class RocketMQApplication {
+
+ public interface MySink {
+
+ @Input("input1")
+ SubscribableChannel input1();
+
+ @Input("input2")
+ SubscribableChannel input2();
+
+ @Input("input3")
+ SubscribableChannel input3();
+
+ }
+
+ public static void main(String[] args) {
+ SpringApplication.run(RocketMQApplication.class, args);
+ }
+
+ @Bean
+ public CustomRunner customRunner() {
+ return new CustomRunner();
+ }
+
+ public static class CustomRunner implements CommandLineRunner {
+ @Autowired
+ private SenderService senderService;
+
+ @Override
+ public void run(String... args) throws Exception {
+ int count = 5;
+ for (int index = 1; index <= count; index++) {
+ String msgContent = "msg-" + index;
+ if (index % 3 == 0) {
+ senderService.send(msgContent);
+ }
+ else if (index % 3 == 1) {
+ senderService.sendWithTags(msgContent, "tagStr");
+ }
+ else {
+ senderService.sendObject(new Foo(index, "foo"), "tagObj");
+ }
+ }
+ }
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SenderService.java b/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SenderService.java
new file mode 100644
index 000000000..eaf0001ff
--- /dev/null
+++ b/spring-cloud-alibaba-examples/rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SenderService.java
@@ -0,0 +1,43 @@
+package org.springframework.cloud.alibaba.cloud.examples;
+
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.rocketmq.common.message.MessageConst;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.stream.messaging.Source;
+import org.springframework.messaging.Message;
+import org.springframework.messaging.MessageHeaders;
+import org.springframework.messaging.support.MessageBuilder;
+import org.springframework.stereotype.Service;
+import org.springframework.util.MimeTypeUtils;
+
+/**
+ * @author Jim
+ */
+@Service
+public class SenderService {
+
+ @Autowired
+ private Source source;
+
+ public void send(String msg) throws Exception {
+ source.output().send(MessageBuilder.withPayload(msg).build());
+ }
+
+ public void sendWithTags(T msg, String tag) throws Exception {
+ Message message = MessageBuilder.createMessage(msg,
+ new MessageHeaders(Stream.of(tag).collect(Collectors
+ .toMap(str -> MessageConst.PROPERTY_TAGS, String::toString))));
+ source.output().send(message);
+ }
+
+ public void sendObject(T msg, String tag) throws Exception {
+ Message message = MessageBuilder.withPayload(msg)
+ .setHeader(MessageConst.PROPERTY_TAGS, tag)
+ .setHeader(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON)
+ .build();
+ source.output().send(message);
+ }
+
+}
diff --git a/spring-cloud-alibaba-examples/rocketmq-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/rocketmq-example/src/main/resources/application.properties
new file mode 100644
index 000000000..2a41b0d9d
--- /dev/null
+++ b/spring-cloud-alibaba-examples/rocketmq-example/src/main/resources/application.properties
@@ -0,0 +1,31 @@
+spring.cloud.stream.default-binder=rocketmq
+
+spring.cloud.stream.rocketmq.binder.namesrv-addr=127.0.0.1:9876
+
+spring.cloud.stream.bindings.output.destination=test-topic
+spring.cloud.stream.bindings.output.content-type=application/json
+
+spring.cloud.stream.bindings.input1.destination=test-topic
+spring.cloud.stream.bindings.input1.content-type=application/json
+spring.cloud.stream.bindings.input1.group=test-group1
+spring.cloud.stream.rocketmq.bindings.input1.consumer.orderly=true
+spring.cloud.stream.bindings.input1.consumer.maxAttempts=1
+
+spring.cloud.stream.bindings.input2.destination=test-topic
+spring.cloud.stream.bindings.input2.content-type=application/json
+spring.cloud.stream.bindings.input2.group=test-group2
+spring.cloud.stream.rocketmq.bindings.input2.consumer.orderly=false
+spring.cloud.stream.rocketmq.bindings.input2.consumer.tags=tagStr
+spring.cloud.stream.bindings.input2.consumer.concurrency=20
+spring.cloud.stream.bindings.input2.consumer.maxAttempts=1
+
+spring.cloud.stream.bindings.input3.destination=test-topic
+spring.cloud.stream.bindings.input3.content-type=application/json
+spring.cloud.stream.bindings.input3.group=test-group3
+spring.cloud.stream.rocketmq.bindings.input3.consumer.tags=tagObj
+spring.cloud.stream.bindings.input3.consumer.concurrency=20
+spring.cloud.stream.bindings.input3.consumer.maxAttempts=1
+
+server.port=28081
+
+management.endpoints.web.exposure.include=*
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml
index 91ae63304..3d5a0b941 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml
@@ -30,6 +30,24 @@
org.springframework.boot
spring-boot-starter-actuator
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/JsonFlowRuleListParser.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/JsonFlowRuleListConverter.java
similarity index 83%
rename from spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/JsonFlowRuleListParser.java
rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/JsonFlowRuleListConverter.java
index b205c96c5..c5cea94df 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/JsonFlowRuleListParser.java
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/JsonFlowRuleListConverter.java
@@ -10,7 +10,7 @@ import com.alibaba.fastjson.TypeReference;
/**
* @author fangjian
*/
-public class JsonFlowRuleListParser implements Converter> {
+public class JsonFlowRuleListConverter implements Converter> {
@Override
public List convert(String source) {
return JSON.parseObject(source, new TypeReference>() {
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ServiceApplication.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ServiceApplication.java
index fe00e033e..2f258d7b8 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ServiceApplication.java
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ServiceApplication.java
@@ -25,8 +25,8 @@ public class ServiceApplication {
}
@Bean
- public Converter myParser() {
- return new JsonFlowRuleListParser();
+ public Converter myConverter() {
+ return new JsonFlowRuleListConverter();
}
public static void main(String[] args) {
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties
index fd8d3b6da..100b40102 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties
@@ -2,13 +2,15 @@ spring.application.name=sentinel-example
server.port=18083
management.endpoints.web.exposure.include=*
spring.cloud.sentinel.transport.port=8721
-spring.cloud.sentinel.transport.dashboard=localhost:8080
+spring.cloud.sentinel.transport.dashboard=localhost:9999
+spring.cloud.sentinel.eager=true
+spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json
+spring.cloud.sentinel.datasource.ds1.file.data-type=json
+#spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json
+#spring.cloud.sentinel.datasource.ds1.file.data-type=custom
+#spring.cloud.sentinel.datasource.ds1.file.converter-class=org.springframework.cloud.alibaba.cloud.examples.JsonFlowRuleListConverter
-spring.cloud.sentinel.datasource.type=file
-spring.cloud.sentinel.datasource.recommendRefreshMs=3000
-spring.cloud.sentinel.datasource.bufSize=4056196
-spring.cloud.sentinel.datasource.charset=utf-8
-spring.cloud.sentinel.datasource.converter=myParser
-spring.cloud.sentinel.datasource.file=/Users/you/rule.json
\ No newline at end of file
+spring.cloud.sentinel.datasource.ds2.file.file=classpath: degraderule.json
+spring.cloud.sentinel.datasource.ds2.file.data-type=json
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/degraderule.json b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/degraderule.json
new file mode 100644
index 000000000..5977c5fcf
--- /dev/null
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/degraderule.json
@@ -0,0 +1,16 @@
+[
+ {
+ "resource": "abc0",
+ "count": 20.0,
+ "grade": 0,
+ "passCount": 0,
+ "timeWindow": 10
+ },
+ {
+ "resource": "abc1",
+ "count": 15.0,
+ "grade": 0,
+ "passCount": 0,
+ "timeWindow": 10
+ }
+]
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/flowrule.json b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/flowrule.json
new file mode 100644
index 000000000..679dff4a4
--- /dev/null
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/flowrule.json
@@ -0,0 +1,26 @@
+[
+ {
+ "resource": "resource",
+ "controlBehavior": 0,
+ "count": 1,
+ "grade": 1,
+ "limitApp": "default",
+ "strategy": 0
+ },
+ {
+ "resource": "p",
+ "controlBehavior": 0,
+ "count": 1,
+ "grade": 1,
+ "limitApp": "default",
+ "strategy": 0
+ },
+ {
+ "resource": "abc",
+ "controlBehavior": 0,
+ "count": 1,
+ "grade": 1,
+ "limitApp": "default",
+ "strategy": 0
+ }
+]
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/flowrule.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/flowrule.xml
new file mode 100644
index 000000000..7f1926d3e
--- /dev/null
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/flowrule.xml
@@ -0,0 +1,21 @@
+
+
+
+ resource
+ 0
+ 1
+ 1
+ default
+ 0
+
+
+ test
+ 0
+ 1
+ 1
+ default
+ 0
+
+
+
+
diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/pom.xml b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/pom.xml
new file mode 100644
index 000000000..22dbca4be
--- /dev/null
+++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/pom.xml
@@ -0,0 +1,54 @@
+
+
+
+ spring-cloud-alibaba-examples
+ org.springframework.cloud
+ 0.2.1.BUILD-SNAPSHOT
+ ../pom.xml
+
+ 4.0.0
+
+ org.springframework.cloud
+ spring-cloud-bus-rocketmq-example
+ Spring Cloud Bus RocketMQ Example
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bus-rocketmq
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ ${maven-deploy-plugin.version}
+
+ true
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/RocketMQBusApplication.java b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/RocketMQBusApplication.java
new file mode 100644
index 000000000..dfae4d832
--- /dev/null
+++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/RocketMQBusApplication.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.cloud.alibaba.cloud.examples.rocketmq;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan;
+import org.springframework.context.ApplicationEventPublisher;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.event.EventListener;
+
+/**
+ * RocketMQ Bus Spring Application
+ *
+ * @author Mercy
+ * @since 0.2.1
+ */
+@EnableAutoConfiguration
+@RemoteApplicationEventScan(basePackages = "org.springframework.cloud.alibaba.cloud.examples.rocketmq")
+public class RocketMQBusApplication {
+
+ public static void main(String[] args) {
+ new SpringApplicationBuilder(RocketMQBusApplication.class)
+ .run(args);
+ }
+
+ /**
+ * Publish the {@link UserRemoteApplicationEvent} to all instances of currentService.
+ *
+ * @param publisher {@link ApplicationEventPublisher}
+ * @param currentService Current application Name
+ * @return {@link ApplicationRunner} instance
+ */
+ @Bean
+ public ApplicationRunner publishEventRunner(ApplicationEventPublisher publisher,
+ @Value("${spring.application.name}") String currentService) {
+ return args -> {
+ User user = new User();
+ user.setName("Mercy Ma");
+ for (int i = 1; i < 10; i++) {
+ user.setId(Long.valueOf(i));
+ publisher.publishEvent(new UserRemoteApplicationEvent(user, currentService, currentService + ":**"));
+ }
+ };
+ }
+
+ /**
+ * Listener on the {@link UserRemoteApplicationEvent}
+ *
+ * @param event {@link UserRemoteApplicationEvent}
+ */
+ @EventListener
+ public void onEvent(UserRemoteApplicationEvent event) {
+ System.out.println("Listener on User : " + event.getUser());
+ }
+}
diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/User.java b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/User.java
new file mode 100644
index 000000000..ae22c92b7
--- /dev/null
+++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/User.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.cloud.alibaba.cloud.examples.rocketmq;
+
+/**
+ * User Domain
+ *
+ * @author Mercy
+ * @since 0.2.1
+ */
+public class User {
+
+ private Long id;
+
+ private String name;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return "User{" +
+ "id=" + id +
+ ", name='" + name + '\'' +
+ '}';
+ }
+}
diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/UserRemoteApplicationEvent.java b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/UserRemoteApplicationEvent.java
new file mode 100644
index 000000000..919e00ead
--- /dev/null
+++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/rocketmq/UserRemoteApplicationEvent.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.cloud.alibaba.cloud.examples.rocketmq;
+
+import org.springframework.cloud.bus.event.RemoteApplicationEvent;
+
+/**
+ * {@link User} {@link RemoteApplicationEvent}
+ *
+ * @author Mercy
+ * @since 0.2.1
+ */
+public class UserRemoteApplicationEvent extends RemoteApplicationEvent {
+
+ public UserRemoteApplicationEvent(User user, String originService,
+ String destinationService) {
+ super(user, originService, destinationService);
+ }
+
+ public User getUser() {
+ return (User) getSource();
+ }
+}
diff --git a/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/resources/application.properties
new file mode 100644
index 000000000..6c57bdfe0
--- /dev/null
+++ b/spring-cloud-alibaba-examples/spring-cloud-bus-rocketmq-example/src/main/resources/application.properties
@@ -0,0 +1,5 @@
+spring.application.name=spring-cloud-bus-rocketmq-example
+
+management.endpoints.web.exposure.include=*
+
+spring.cloud.bus.trace.enabled=true
\ No newline at end of file
diff --git a/spring-cloud-alibaba-sentinel-datasource/pom.xml b/spring-cloud-alibaba-sentinel-datasource/pom.xml
index f2878dfe1..5d7d85154 100644
--- a/spring-cloud-alibaba-sentinel-datasource/pom.xml
+++ b/spring-cloud-alibaba-sentinel-datasource/pom.xml
@@ -41,8 +41,27 @@
true
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ provided
+
+
+
+ com.fasterxml.jackson.dataformat
+ jackson-dataformat-xml
+ provided
+
+
+
+ org.springframework.boot
+ spring-boot-configuration-processor
+ provided
+ true
+
+
org.springframework.boot
spring-boot
@@ -63,7 +82,6 @@
test
-
diff --git a/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/DataSourceLoader.java b/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/DataSourceLoader.java
deleted file mode 100644
index 40f17197d..000000000
--- a/spring-cloud-alibaba-sentinel-datasource/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/DataSourceLoader.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright (C) 2018 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.alibaba.sentinel.datasource;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
-import org.springframework.core.io.support.PropertiesLoaderUtils;
-import org.springframework.core.io.support.ResourcePatternResolver;
-import org.springframework.util.Assert;
-import org.springframework.util.ClassUtils;
-
-import static org.springframework.core.io.support.ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX;
-
-/**
- * {@link ReadableDataSource} Loader
- *
- * @author Jim
- */
-public class DataSourceLoader {
-
- private static final Logger logger = LoggerFactory.getLogger(DataSourceLoader.class);
-
- private final static String PROPERTIES_RESOURCE_LOCATION = "META-INF/sentinel-datasource.properties";
-
- private final static String ALL_PROPERTIES_RESOURCES_LOCATION = CLASSPATH_ALL_URL_PREFIX
- + PROPERTIES_RESOURCE_LOCATION;
-
- private final static ConcurrentMap> dataSourceClassesCache
- = new ConcurrentHashMap>(
- 4);
-
- static void loadAllDataSourceClassesCache() {
- Map> dataSourceClassesMap = loadAllDataSourceClassesCache(
- ALL_PROPERTIES_RESOURCES_LOCATION);
-
- dataSourceClassesCache.putAll(dataSourceClassesMap);
- }
-
- static Map> loadAllDataSourceClassesCache(
- String resourcesLocation) {
-
- Map> dataSourcesMap
- = new HashMap>(
- 4);
-
- ClassLoader classLoader = DataSourceLoader.class.getClassLoader();
-
- ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
-
- try {
-
- Resource[] resources = resolver.getResources(resourcesLocation);
-
- for (Resource resource : resources) {
- if (resource.exists()) {
- Properties properties = PropertiesLoaderUtils
- .loadProperties(resource);
- for (Map.Entry