diff --git a/README-zh.md b/README-zh.md index 8159af1a0..32b4098f1 100644 --- a/README-zh.md +++ b/README-zh.md @@ -42,7 +42,7 @@ Spring Cloud 使用 Maven 来构建,最快的使用方式是将本项目clone Example 列表: -[sentinel example](https://github.com/spring-cloud-incubator/spring-cloud-alibabacloud/blob/master/spring-cloud-alibaba-examples/sentinel-example/readme-zh.md) +[Sentinel Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md) [Nacos Config Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme-zh.md) diff --git a/README.md b/README.md index 7f3e82bcc..0811db0af 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ A `spring-cloud-alibaba-examples` module is included in our project for you to g Examples: -[Sentinel example](https://github.com/spring-cloud-incubator/spring-cloud-alibabacloud/blob/master/spring-cloud-alibaba-examples/sentinel-example/readme.md) +[Sentinel Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md) [Nacos Config Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-config-example/readme.md) diff --git a/spring-cloud-alibaba-examples/pom.xml b/spring-cloud-alibaba-examples/pom.xml index 37dff7ded..e4c9fa155 100644 --- a/spring-cloud-alibaba-examples/pom.xml +++ b/spring-cloud-alibaba-examples/pom.xml @@ -16,12 +16,12 @@ Example showing how to use features of Spring Cloud Alibaba - sentinel-example + sentinel-example/sentinel-core-example + sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example + sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example + sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api nacos-example/nacos-discovery-example nacos-example/nacos-config-example - sentinel-dubbo-provider-example - sentinel-dubbo-consumer-example - sentinel-dubbo-api storage-example diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/readme-zh.md b/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/readme-zh.md deleted file mode 100644 index fa8cb389a..000000000 --- a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/readme-zh.md +++ /dev/null @@ -1,101 +0,0 @@ -# Sentinel Dubbo Provider Example - -## 项目说明 - -本项目演示如何使用 Sentinel starter 完成 Dubbo 应用的限流管理。 - -[Sentinel](https://github.com/alibaba/Sentinel) 是阿里巴巴开源的分布式系统的流量防卫组件,Sentinel 把流量作为切入点,从流量控制,熔断降级,系统负载保护等多个维度保护服务的稳定性。 - -[Dubbo](http://dubbo.apache.org/)是一款高性能Java RPC框架,有对应的[SpringBoot工程](https://github.com/apache/incubator-dubbo-spring-boot-project)。 - -本项目需要配合`sentinel-dubbo-consumer-example`模块一起完成演示。 - -本项目专注于Sentinel与Dubbo的整合,关于Sentinel的更多特性可以查看[sentinel-example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples/sentinel-example)。 - -## 示例 - -### 如何接入 -在启动示例进行演示之前,我们先了解一下 Dubbo 如何接入 Sentinel。 -**注意 本章节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您无需再进行修改。** - -1. 首先,修改 pom.xml 文件,引入 Sentinel starter 和 Dubbo starter。 - - - org.springframework.cloud - spring-cloud-starter-alibaba-sentinel - - - - com.alibaba.boot - dubbo-spring-boot-starter - - -2. 配置限流规则 - - Sentinel提供了[sentinel-dubbo-adapter](https://github.com/alibaba/Sentinel/tree/master/sentinel-adapter/sentinel-dubbo-adapter)模块用来支持Dubbo服务调用的限流降级。sentinel-starter默认也集成了该功能。 - - sentinel-dubbo-adapter内部的Dubbo Filter会根据资源名进行限流降级处理。只需要配置规则即可: - - FlowRule flowRule = new FlowRule(); - flowRule.setResource("dubboResource"); - flowRule.setCount(10); - flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); - flowRule.setLimitApp("default"); - FlowRuleManager.loadRules(Collections.singletonList(flowRule)); - - -### 服务定义及发布 - -在application.properties文件中定义dubbo相关的配置,比如协议,注册中心: - - spring.application.name = dubbo-provider-demo - - foo.service.version = 1.0.0 - - dubbo.scan.basePackages = org.springframework.cloud.alibaba.cloud.examples - - dubbo.application.id = dubbo-provider-demo - dubbo.application.name = dubbo-provider-demo - - dubbo.protocol.id = dubbo - dubbo.protocol.name = dubbo - dubbo.protocol.port = 12345 - dubbo.protocol.status = server - - dubbo.registry.id = my-registry - dubbo.registry.address = N/A - - -`sentinel-dubbo-api`模块中定义了FooService服务,内容如下: - - package org.springframework.cloud.alibaba.cloud.examples.FooService; - public interface FooService { - String hello(String name); - } - -定义具体的服务: - - @Service( - version = "${foo.service.version}", - application = "${dubbo.application.id}", - protocol = "${dubbo.protocol.id}", - registry = "${dubbo.registry.id}" - ) - public class FooServiceImpl implements FooService { - - @Override - public String hello(String name) { - return "hello, " + name; - } - } - - -### 应用启动 - - -支持 IDE 直接启动和编译打包后启动。 - -1. IDE直接启动:找到主类 `SentinelDubboProviderApp`,执行 main 方法启动应用。 -2. 打包编译后启动:首先执行 `mvn clean package` 将工程编译打包,然后执行 `java -jar sentinel-dubbo-provider-example.jar`启动应用。 - - diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/readme.md b/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/readme.md deleted file mode 100644 index 66234b61b..000000000 --- a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/readme.md +++ /dev/null @@ -1,97 +0,0 @@ -# Sentinel Dubbo Provider Example -## Project Instruction - -This example illustrates how to use Sentinel starter to implement flow control for Spring Cloud applications. - -[Sentinel](https://github.com/alibaba/Sentinel) is an open-source project of Alibaba. Sentinel takes "traffic flow" as the breakthrough point, and provides solutions in areas such as flow control, concurrency, circuit breaking, and load protection to protect service stability. - -[Dubbo](http://dubbo.apache.org/) is a high-performance, java based open source RPC framework. - -This example work with 'sentinel-dubbo-consumer-example' module and `sentinel-dubbo-provider-example` module should startup firstly. - -This example focus on the integration of Sentinel and Dubbo. You can see more features on [sentinel-example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples/sentinel-example). - -## Demo - -### Connect to Sentinel -Before we start the demo, let's learn how to connect Sentinel with Dubbo to a Spring Cloud application. -**Note: This section is to show you how to connect to Sentinel. The configurations have been completed in the following example, so you don't need modify the code any more.** - -1. Add dependency spring-cloud-starter-alibaba-sentinel and dubbo-spring-boot-starter in the pom.xml file in your Spring Cloud project. - - - org.springframework.cloud - spring-cloud-starter-alibaba-sentinel - - - - com.alibaba.boot - dubbo-spring-boot-starter - - -2. Configure flow control rules - - Sentinel provide [sentinel-dubbo-adapter](https://github.com/alibaba/Sentinel/tree/master/sentinel-adapter/sentinel-dubbo-adapter) module to support dubbo. to support dubbo. sentinel-starter integrates this feature by default. - - sentinel-dubbo-adapter will using Sentinel to handle resource by Dubbo Filter. You just need to define rules. - - FlowRule flowRule = new FlowRule(); - flowRule.setResource("dubboResource"); - flowRule.setCount(10); - flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); - flowRule.setLimitApp("default"); - FlowRuleManager.loadRules(Collections.singletonList(flowRule)); - -### Configure and Publish Service - -Define some configs of dubbo in `application.properties`, like protocol, config registry: - - spring.application.name = dubbo-provider-demo - - foo.service.version = 1.0.0 - - dubbo.scan.basePackages = org.springframework.cloud.alibaba.cloud.examples - - dubbo.application.id = dubbo-provider-demo - dubbo.application.name = dubbo-provider-demo - - dubbo.protocol.id = dubbo - dubbo.protocol.name = dubbo - dubbo.protocol.port = 12345 - dubbo.protocol.status = server - - dubbo.registry.id = my-registry - dubbo.registry.address = N/A - - -`sentinel-dubbo-api` define a service named FooService: - - package org.springframework.cloud.alibaba.cloud.examples.FooService; - public interface FooService { - String hello(String name); - } - -Define the implement Service annotated by `@Service`: - - @Service( - version = "${foo.service.version}", - application = "${dubbo.application.id}", - protocol = "${dubbo.protocol.id}", - registry = "${dubbo.registry.id}" - ) - public class FooServiceImpl implements FooService { - - @Override - public String hello(String name) { - return "hello, " + name; - } - } - -### Start Application - -Start the application in IDE or by building a fatjar. - -1. Start in IDE: Find main class `SentinelDubboProviderApp`, and execute the main method. -2. Build a fatjar:Execute command `mvn clean package` to build a fatjar,and run command `java -jar sentinel-dubbo-provider-example.jar` to start the application. - - diff --git a/spring-cloud-alibaba-examples/sentinel-example/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml similarity index 94% rename from spring-cloud-alibaba-examples/sentinel-example/pom.xml rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml index 97bed58b8..ec35b244d 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/pom.xml +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/pom.xml @@ -6,11 +6,12 @@ org.springframework.cloud spring-cloud-alibaba-examples 0.2.0.BUILD-SNAPSHOT + ../../pom.xml 4.0.0 - sentinel-example + sentinel-core-example jar Example demonstrating how to use sentinel diff --git a/spring-cloud-alibaba-examples/sentinel-example/readme-zh.md b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md similarity index 99% rename from spring-cloud-alibaba-examples/sentinel-example/readme-zh.md rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md index eb261a51d..49d1e8989 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/readme-zh.md +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md @@ -84,7 +84,7 @@ 2. 启动应用,支持 IDE 直接启动和编译打包后启动。 1. IDE直接启动:找到主类 `ServiceApplication`,执行 main 方法启动应用。 - 2. 打包编译后启动:首先执行 `mvn clean package` 将工程编译打包,然后执行 `java -jar sentinel-example.jar`启动应用。 + 2. 打包编译后启动:首先执行 `mvn clean package` 将工程编译打包,然后执行 `java -jar sentinel-core-example.jar`启动应用。 ### 调用服务 diff --git a/spring-cloud-alibaba-examples/sentinel-example/readme.md b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md similarity index 99% rename from spring-cloud-alibaba-examples/sentinel-example/readme.md rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md index 6f3b4bd8b..86156b53a 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/readme.md +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md @@ -71,7 +71,7 @@ Before we start the demo, let's learn how to connect Sentinel to a Spring Cloud 2. Start the application in IDE or by building a fatjar. 1. Start in IDE: Find main class `ServiceApplication`, and execute the main method. - 2. Build a fatjar:Execute command `mvn clean package` to build a fatjar,and run command `java -jar sentinel-example.jar` to start the application. + 2. Build a fatjar:Execute command `mvn clean package` to build a fatjar,and run command `java -jar sentinel-core-example.jar` to start the application. ### Invoke Service diff --git a/spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ExceptionUtil.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ExceptionUtil.java similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ExceptionUtil.java rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ExceptionUtil.java diff --git a/spring-cloud-alibaba-examples/sentinel-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/JsonFlowRuleListParser.java similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-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/JsonFlowRuleListParser.java diff --git a/spring-cloud-alibaba-examples/sentinel-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 similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ServiceApplication.java rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/ServiceApplication.java diff --git a/spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestController.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestController.java similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestController.java rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/TestController.java diff --git a/spring-cloud-alibaba-examples/sentinel-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-example/src/main/resources/application.properties rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/src/main/resources/application.properties diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/readme-zh.md b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/readme-zh.md similarity index 63% rename from spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/readme-zh.md rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/readme-zh.md index 21ed3b14b..0a26836bf 100644 --- a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/readme-zh.md +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/readme-zh.md @@ -1,4 +1,4 @@ -# Sentinel Dubbo Consumer Example +# Sentinel Dubbo Example ## 项目说明 @@ -8,9 +8,7 @@ [Dubbo](http://dubbo.apache.org/)是一款高性能Java RPC框架,有对应的[SpringBoot工程](https://github.com/apache/incubator-dubbo-spring-boot-project)。 -本项目需要配合`sentinel-dubbo-provider-example`模块一起完成演示,并且需要先启动sentinel-dubbo-provider-example。 - -本项目专注于Sentinel与Dubbo的整合,关于Sentinel的更多特性可以查看[sentinel-example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples/sentinel-example)。 +本项目专注于Sentinel与Dubbo的整合,关于Sentinel的更多特性可以查看[sentinel-core-example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example)。 ## 示例 @@ -37,14 +35,61 @@ sentinel-dubbo-adapter内部的Dubbo Filter会根据资源名进行限流降级处理。只需要配置规则即可: FlowRule flowRule = new FlowRule(); - flowRule.setResource( - "org.springframework.cloud.alibaba.cloud.examples.FooService:hello(java.lang.String)"); + flowRule.setResource("dubboResource"); flowRule.setCount(10); flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); flowRule.setLimitApp("default"); FlowRuleManager.loadRules(Collections.singletonList(flowRule)); -### 规则定义 + +### 服务定义及发布 + +Provider端在application.properties文件中定义dubbo相关的配置,比如协议,注册中心: + + spring.application.name = dubbo-provider-demo + + foo.service.version = 1.0.0 + + dubbo.scan.basePackages = org.springframework.cloud.alibaba.cloud.examples + + dubbo.application.id = dubbo-provider-demo + dubbo.application.name = dubbo-provider-demo + + dubbo.protocol.id = dubbo + dubbo.protocol.name = dubbo + dubbo.protocol.port = 12345 + dubbo.protocol.status = server + + dubbo.registry.id = my-registry + dubbo.registry.address = N/A + + +`sentinel-dubbo-api`模块中定义了FooService服务,内容如下: + + package org.springframework.cloud.alibaba.cloud.examples.FooService; + public interface FooService { + String hello(String name); + } + +定义具体的服务: + + @Service( + version = "${foo.service.version}", + application = "${dubbo.application.id}", + protocol = "${dubbo.protocol.id}", + registry = "${dubbo.registry.id}" + ) + public class FooServiceImpl implements FooService { + + @Override + public String hello(String name) { + return "hello, " + name; + } + } + +### 服务调用 + +Consumer端在服务调用之前,先定义限流规则。 `sentinel-dubbo-api`模块中定义了FooService服务,内容如下: @@ -58,15 +103,13 @@ 定义该资源名对应的限流规则: FlowRule flowRule = new FlowRule(); - flowRule.setResource("dubboResource"); + flowRule.setResource("org.springframework.cloud.alibaba.cloud.examples.dubbo.FooService:hello(java.lang.String)"); flowRule.setCount(10); flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); flowRule.setLimitApp("default"); FlowRuleManager.loadRules(Collections.singletonList(flowRule)); -### 服务调用 - -根据`sentinel-dubbo-provider-example`中发布的定义,使用Dubbo的@Reference注解注入服务对应的Bean。 +根据Provider端中发布的定义,使用Dubbo的@Reference注解注入服务对应的Bean: @Reference(version = "${foo.service.version}", application = "${dubbo.application.id}", url = "dubbo://localhost:12345", timeout = 30000) @@ -91,9 +134,15 @@ ### 应用启动 + 支持 IDE 直接启动和编译打包后启动。 -1. IDE直接启动:找到主类 `SentinelDubboConsumerApp`,执行 main 方法启动应用。 -2. 打包编译后启动:首先执行 `mvn clean package` 将工程编译打包,然后执行 `java -jar sentinel-dubbo-consumer-example.jar`启动应用。 +Provider端: + +1. IDE直接启动:找到主类 `SentinelDubboProviderApp`,执行 main 方法启动应用。 +2. 打包编译后启动:首先执行 `mvn clean package` 将工程编译打包,然后执行 `java -jar sentinel-dubbo-provider-example.jar`启动应用。 +Consumer端: +1. IDE直接启动:找到主类 `SentinelDubboConsumerApp`,执行 main 方法启动应用。 +2. 打包编译后启动:首先执行 `mvn clean package` 将工程编译打包,然后执行 `java -jar sentinel-dubbo-consumer-example.jar`启动应用。 diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/readme.md b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/readme.md similarity index 62% rename from spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/readme.md rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/readme.md index 6ce6122af..2bfcaec9e 100644 --- a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/readme.md +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/readme.md @@ -1,4 +1,4 @@ -# Sentinel Dubbo Consumer Example +# Sentinel Dubbo Example ## Project Instruction This example illustrates how to use Sentinel starter to implement flow control for Spring Cloud applications. @@ -7,9 +7,7 @@ This example illustrates how to use Sentinel starter to implement flow control f [Dubbo](http://dubbo.apache.org/) is a high-performance, java based open source RPC framework. -This example work with 'sentinel-dubbo-provider-example' module and `sentinel-dubbo-provider-example` module should startup firstly. - -This example focus on the integration of Sentinel and Dubbo. You can see more features on [sentinel-example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples/sentinel-example). +This example focus on the integration of Sentinel and Dubbo. You can see more features on [sentinel-core-example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/tree/master/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example). ## Demo @@ -42,7 +40,54 @@ Before we start the demo, let's learn how to connect Sentinel with Dubbo to a Sp flowRule.setLimitApp("default"); FlowRuleManager.loadRules(Collections.singletonList(flowRule)); -### Configure Rules +### Configure and Publish Service + +Define some configs of dubbo in `application.properties` in provider side, like protocol, config registry : + + spring.application.name = dubbo-provider-demo + + foo.service.version = 1.0.0 + + dubbo.scan.basePackages = org.springframework.cloud.alibaba.cloud.examples + + dubbo.application.id = dubbo-provider-demo + dubbo.application.name = dubbo-provider-demo + + dubbo.protocol.id = dubbo + dubbo.protocol.name = dubbo + dubbo.protocol.port = 12345 + dubbo.protocol.status = server + + dubbo.registry.id = my-registry + dubbo.registry.address = N/A + + +`sentinel-dubbo-api` define a service named FooService: + + package org.springframework.cloud.alibaba.cloud.examples.FooService; + public interface FooService { + String hello(String name); + } + +Define the implement Service annotated by `@Service`: + + @Service( + version = "${foo.service.version}", + application = "${dubbo.application.id}", + protocol = "${dubbo.protocol.id}", + registry = "${dubbo.registry.id}" + ) + public class FooServiceImpl implements FooService { + + @Override + public String hello(String name) { + return "hello, " + name; + } + } + +### Service Invocation + +We will configure flow control rules before service invocation in consumer side. `sentinel-dubbo-api` define a service named FooService: @@ -53,17 +98,15 @@ Before we start the demo, let's learn how to connect Sentinel with Dubbo to a Sp The resource name of this service's `hello` method is `org.springframework.cloud.alibaba.cloud.examples.dubbo.FooService:hello(java.lang.String)` . -Configure rules: +Configure rules: FlowRule flowRule = new FlowRule(); - flowRule.setResource("dubboResource"); + flowRule.setResource("org.springframework.cloud.alibaba.cloud.examples.dubbo.FooService:hello(java.lang.String)"); flowRule.setCount(10); flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS); flowRule.setLimitApp("default"); FlowRuleManager.loadRules(Collections.singletonList(flowRule)); -### Service Invocation - Using the `@Reference` annotation to inject service: @Reference(version = "${foo.service.version}", application = "${dubbo.application.id}", @@ -91,7 +134,12 @@ Because QPS is 10, we can see that flow control takes effect in this invocation: Start the application in IDE or by building a fatjar. -1. Start in IDE: Find main class `SentinelDubboConsumerApp`, and execute the main method. -2. Build a fatjar:Execute command `mvn clean package` to build a fatjar,and run command `java -jar sentinel-dubbo-consumer-example.jar` to start the application. +Provider side: + +1. Start in IDE: Find main class `SentinelDubboProviderApp`, and execute the main method. +2. Build a fatjar: Execute command `mvn clean package` to build a fatjar, and run command `java -jar sentinel-dubbo-provider-example.jar` to start the application. +Consumer side: +1. Start in IDE: Find main class `SentinelDubboConsumerApp`, and execute the main method. +2. Build a fatjar: Execute command `mvn clean package` to build a fatjar, and run command `java -jar sentinel-dubbo-consumer-example.jar` to start the application. diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-api/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/pom.xml similarity index 95% rename from spring-cloud-alibaba-examples/sentinel-dubbo-api/pom.xml rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/pom.xml index 376f2a96a..24cde890d 100644 --- a/spring-cloud-alibaba-examples/sentinel-dubbo-api/pom.xml +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/pom.xml @@ -6,6 +6,7 @@ org.springframework.cloud spring-cloud-alibaba-examples 0.2.0.BUILD-SNAPSHOT + ../../../pom.xml 4.0.0 diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-api/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooService.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooService.java similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-dubbo-api/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooService.java rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooService.java diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/pom.xml similarity index 97% rename from spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/pom.xml rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/pom.xml index ca3a2538c..890656ea8 100644 --- a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/pom.xml +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/pom.xml @@ -6,6 +6,7 @@ org.springframework.cloud spring-cloud-alibaba-examples 0.2.0.BUILD-SNAPSHOT + ../../../pom.xml 4.0.0 diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceConsumer.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceConsumer.java similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceConsumer.java rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceConsumer.java diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboConsumerApp.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboConsumerApp.java similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboConsumerApp.java rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboConsumerApp.java diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/resources/application.properties similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-dubbo-consumer-example/src/main/resources/application.properties rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-consumer-example/src/main/resources/application.properties diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/pom.xml b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/pom.xml similarity index 97% rename from spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/pom.xml rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/pom.xml index f1a0a832c..87adbbaf7 100644 --- a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/pom.xml +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/pom.xml @@ -6,6 +6,7 @@ org.springframework.cloud spring-cloud-alibaba-examples 0.2.0.BUILD-SNAPSHOT + ../../../pom.xml 4.0.0 diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceImpl.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceImpl.java similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceImpl.java rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/FooServiceImpl.java diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboProviderApp.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboProviderApp.java similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboProviderApp.java rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/java/org/springframework/cloud/alibaba/cloud/examples/SentinelDubboProviderApp.java diff --git a/spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/src/main/resources/application.properties b/spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/resources/application.properties similarity index 100% rename from spring-cloud-alibaba-examples/sentinel-dubbo-provider-example/src/main/resources/application.properties rename to spring-cloud-alibaba-examples/sentinel-example/sentinel-dubbo-example/sentinel-dubbo-provider-example/src/main/resources/application.properties