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

polish #761 update pkg name & maven coordinate for Greenwich

This commit is contained in:
fangjian0423
2019-07-23 11:03:04 +08:00
parent 3998ea23f7
commit 883c66f251
599 changed files with 4993 additions and 4526 deletions

View File

@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.9.1.BUILD-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
@@ -18,7 +18,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

View File

@@ -15,7 +15,7 @@ Before we start the demo, let's learn how to connect Sentinel to a Spring Cloud
1. Add dependency spring-cloud-starter-alibaba-sentinel in the pom.xml file in your Spring Cloud project.
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

View File

@@ -1,9 +1,9 @@
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import org.springframework.cloud.alibaba.sentinel.rest.SentinelClientHttpResponse;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import com.alibaba.cloud.sentinel.rest.SentinelClientHttpResponse;
import com.alibaba.csp.sentinel.slots.block.BlockException;
/**

View File

@@ -1,11 +1,11 @@
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import com.alibaba.cloud.sentinel.annotation.SentinelRestTemplate;
import com.alibaba.csp.sentinel.datasource.Converter;
/**

View File

@@ -1,4 +1,4 @@
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -24,15 +24,15 @@ public class TestController {
}
@RequestMapping(value = "/aa", method = RequestMethod.GET)
@SentinelResource("aa")
@SentinelResource("aa")
public String aa(int b, int a) {
return "Hello test";
}
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test1() {
return "Hello test";
}
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test1() {
return "Hello test";
}
@RequestMapping(value = "/template", method = RequestMethod.GET)
public String client() {

View File

@@ -50,7 +50,7 @@ Provider端在application.properties文件中定义dubbo相关的配置比如
foo.service.version = 1.0.0
dubbo.scan.basePackages = org.springframework.cloud.alibaba.cloud.examples
dubbo.scan.basePackages = com.alibaba.cloud.examples
dubbo.application.id = dubbo-provider-demo
dubbo.application.name = dubbo-provider-demo
@@ -66,7 +66,7 @@ Provider端在application.properties文件中定义dubbo相关的配置比如
`sentinel-dubbo-api`模块中定义了FooService服务内容如下
package org.springframework.cloud.alibaba.cloud.examples.FooService;
package FooService;
public interface FooService {
String hello(String name);
}
@@ -93,17 +93,17 @@ Consumer端在服务调用之前先定义限流规则。
`sentinel-dubbo-api`模块中定义了FooService服务内容如下
package org.springframework.cloud.alibaba.cloud.examples.FooService;
package FooService;
public interface FooService {
String hello(String name);
}
该服务在Sentinel下对应的资源名是 `org.springframework.cloud.alibaba.cloud.examples.dubbo.FooService:hello(java.lang.String)`
该服务在Sentinel下对应的资源名是 `com.alibaba.cloud.examples.FooService:hello(java.lang.String)`
定义该资源名对应的限流规则:
FlowRule flowRule = new FlowRule();
flowRule.setResource("org.springframework.cloud.alibaba.cloud.examples.dubbo.FooService:hello(java.lang.String)");
flowRule.setResource("com.alibaba.cloud.examples.FooService:hello(java.lang.String)");
flowRule.setCount(10);
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
flowRule.setLimitApp("default");

View File

@@ -18,7 +18,7 @@ Before we start the demo, let's learn how to connect Sentinel with Dubbo to a Sp
1. Add dependency spring-cloud-starter-alibaba-sentinel and dubbo-spring-boot-starter in the pom.xml file in your Spring Cloud project.
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
@@ -48,7 +48,7 @@ Define some configs of dubbo in `application.properties` in provider side, like
foo.service.version = 1.0.0
dubbo.scan.basePackages = org.springframework.cloud.alibaba.cloud.examples
dubbo.scan.basePackages = com.alibaba.cloud.examples
dubbo.application.id = dubbo-provider-demo
dubbo.application.name = dubbo-provider-demo
@@ -64,7 +64,7 @@ Define some configs of dubbo in `application.properties` in provider side, like
`sentinel-dubbo-api` define a service named FooService:
package org.springframework.cloud.alibaba.cloud.examples.FooService;
package FooService;
public interface FooService {
String hello(String name);
}
@@ -91,17 +91,17 @@ We will configure flow control rules before service invocation in consumer side.
`sentinel-dubbo-api` define a service named FooService:
package org.springframework.cloud.alibaba.cloud.examples.FooService;
package FooService;
public interface FooService {
String hello(String name);
}
The resource name of this service's `hello` method is `org.springframework.cloud.alibaba.cloud.examples.dubbo.FooService:hello(java.lang.String)` .
The resource name of this service's `hello` method is `com.alibaba.cloud.examples.FooService:hello(java.lang.String)` .
Configure rules:
FlowRule flowRule = new FlowRule();
flowRule.setResource("org.springframework.cloud.alibaba.cloud.examples.dubbo.FooService:hello(java.lang.String)");
flowRule.setResource("com.alibaba.cloud.examples.FooService:hello(java.lang.String)");
flowRule.setCount(10);
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
flowRule.setLimitApp("default");

View File

@@ -3,14 +3,14 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.9.1.BUILD-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba.cloud</groupId>
<artifactId>sentinel-dubbo-api</artifactId>
<packaging>jar</packaging>
<description>api for sentinel dubbo example</description>

View File

@@ -0,0 +1,10 @@
package com.alibaba.cloud.examples;
/**
* @author fangjian
*/
public interface FooService {
String hello(String name);
}

View File

@@ -1,10 +0,0 @@
package org.springframework.cloud.alibaba.cloud.examples;
/**
* @author fangjian
*/
public interface FooService {
String hello(String name);
}

View File

@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.9.1.BUILD-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
@@ -18,12 +18,12 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>sentinel-dubbo-api</artifactId>
</dependency>

View File

@@ -1,4 +1,4 @@
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import java.util.Collections;
@@ -16,7 +16,7 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
/**
* @author fangjian
*/
@SpringBootApplication(scanBasePackages = "org.springframework.cloud.alibaba.cloud.examples")
@SpringBootApplication(scanBasePackages = "com.alibaba.cloud.examples")
public class SentinelDubboConsumerApp {
@Bean
@@ -27,8 +27,7 @@ public class SentinelDubboConsumerApp {
public static void main(String[] args) {
FlowRule flowRule = new FlowRule();
flowRule.setResource(
"org.springframework.cloud.alibaba.cloud.examples.FooService:hello(java.lang.String)");
flowRule.setResource("com.alibaba.cloud.examples.FooService:hello(java.lang.String)");
flowRule.setCount(10);
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
flowRule.setLimitApp("default");

View File

@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.9.1.BUILD-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
@@ -18,12 +18,12 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>sentinel-dubbo-api</artifactId>
</dependency>

View File

@@ -2,7 +2,7 @@ spring.application.name = dubbo-provider-demo
foo.service.version = 1.0.0
dubbo.scan.basePackages = org.springframework.cloud.alibaba.cloud.examples
dubbo.scan.basePackages = com.alibaba.cloud.examples
dubbo.application.id = dubbo-provider-demo
dubbo.application.name = dubbo-provider-demo

View File

@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.9.1.BUILD-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
@@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
@@ -39,7 +39,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>

View File

@@ -14,18 +14,19 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
import static org.springframework.web.reactive.function.BodyInserters.fromObject;
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
import reactor.core.publisher.Mono;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
@@ -33,16 +34,17 @@ import static org.springframework.web.reactive.function.BodyInserters.fromObject
@Configuration
public class MySCGConfiguration {
@Bean
public BlockRequestHandler blockRequestHandler() {
return new BlockRequestHandler() {
@Override
public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable t) {
return ServerResponse.status(444)
.contentType(MediaType.APPLICATION_JSON_UTF8)
.body(fromObject("SCS Sentinel block"));
}
};
}
@Bean
public BlockRequestHandler blockRequestHandler() {
return new BlockRequestHandler() {
@Override
public Mono<ServerResponse> handleRequest(ServerWebExchange exchange,
Throwable t) {
return ServerResponse.status(444)
.contentType(MediaType.APPLICATION_JSON_UTF8)
.body(fromObject("SCS Sentinel block"));
}
};
}
}

View File

@@ -14,11 +14,14 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import java.util.List;
import java.util.Set;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager;
import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
@@ -26,8 +29,6 @@ import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
/**
@@ -36,19 +37,19 @@ import reactor.core.publisher.Mono;
@RestController
public class RulesWebFluxController {
@GetMapping("/api")
public Mono<Set<ApiDefinition>> apiRules() {
return Mono.just(GatewayApiDefinitionManager.getApiDefinitions());
}
@GetMapping("/api")
public Mono<Set<ApiDefinition>> apiRules() {
return Mono.just(GatewayApiDefinitionManager.getApiDefinitions());
}
@GetMapping("/gateway")
public Mono<Set<GatewayFlowRule>> apiGateway() {
return Mono.just(GatewayRuleManager.getRules());
}
@GetMapping("/gateway")
public Mono<Set<GatewayFlowRule>> apiGateway() {
return Mono.just(GatewayRuleManager.getRules());
}
@GetMapping("/flow")
public Mono<List<FlowRule>> apiFlow() {
return Mono.just(FlowRuleManager.getRules());
}
@GetMapping("/flow")
public Mono<List<FlowRule>> apiFlow() {
return Mono.just(FlowRuleManager.getRules());
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -25,9 +25,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SentinelSpringCloudGatewayApplication {
public static void main(String[] args) {
//GatewayCallbackManager.setRequestOriginParser(s -> "123");
SpringApplication.run(SentinelSpringCloudGatewayApplication.class, args);
}
public static void main(String[] args) {
// GatewayCallbackManager.setRequestOriginParser(s -> "123");
SpringApplication.run(SentinelSpringCloudGatewayApplication.class, args);
}
}

View File

@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.9.1.BUILD-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
@@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import static org.springframework.web.reactive.function.BodyInserters.fromObject;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -37,6 +37,13 @@ public class SentinelWebFluxController {
.transform(new SentinelReactorTransformer<>("mono"));
}
@GetMapping("/test")
public Mono<String> test() {
return Mono.just("simple string")
// transform the publisher here.
.transform(new SentinelReactorTransformer<>("test"));
}
@GetMapping("/flux")
public Flux<String> flux() {
return Flux.fromArray(new String[] { "a", "b", "c" })

View File

@@ -1,4 +1,4 @@
spring.application.name=sentinel-example
spring.application.name=sentinel-webflux-example
server.port=18084
management.endpoints.web.exposure.include=*
spring.cloud.sentinel.transport.dashboard=localhost:8080

View File

@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.9.1.BUILD-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
@@ -19,7 +19,7 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
@@ -39,7 +39,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import java.util.List;
import java.util.Set;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -27,8 +27,8 @@ import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@EnableZuulProxy
public class SentinelZuulApplication {
public static void main(String[] args) {
SpringApplication.run(SentinelZuulApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(SentinelZuulApplication.class, args);
}
}

View File

@@ -14,53 +14,55 @@
* limitations under the License.
*/
package org.springframework.cloud.alibaba.cloud.examples;
package com.alibaba.cloud.examples;
import javax.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.alibaba.csp.sentinel.adapter.gateway.zuul.callback.RequestOriginParser;
import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.BlockResponse;
import com.alibaba.csp.sentinel.adapter.gateway.zuul.fallback.ZuulBlockFallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
*/
@Configuration
public class ZuulConfiguration {
@Bean
public ZuulBlockFallbackProvider zuulBlockFallbackProvider1() {
return new ZuulBlockFallbackProvider() {
@Override
public String getRoute() {
return "*";
}
@Bean
public ZuulBlockFallbackProvider zuulBlockFallbackProvider1() {
return new ZuulBlockFallbackProvider() {
@Override
public String getRoute() {
return "*";
}
@Override
public BlockResponse fallbackResponse(String route, Throwable cause) {
if (route.equals("my-service3")) {
return new BlockResponse(433, "Sentinel Block3", route);
} else if (route.equals("my-service4")) {
return new BlockResponse(444, "my-service4", route);
} else {
return new BlockResponse(499, "Sentinel Block 499", route);
}
}
};
}
@Override
public BlockResponse fallbackResponse(String route, Throwable cause) {
if (route.equals("my-service3")) {
return new BlockResponse(433, "Sentinel Block3", route);
}
else if (route.equals("my-service4")) {
return new BlockResponse(444, "my-service4", route);
}
else {
return new BlockResponse(499, "Sentinel Block 499", route);
}
}
};
}
@Bean
public RequestOriginParser requestOriginParser() {
return new RequestOriginParser() {
@Bean
public RequestOriginParser requestOriginParser() {
return new RequestOriginParser() {
@Override
public String parseOrigin(HttpServletRequest request) {
return "123";
}
};
}
@Override
public String parseOrigin(HttpServletRequest request) {
return "123";
}
};
}
}