diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..29a3a06c544409d750b27dbcb3be86716cd01228 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/workspace.xml + +/misc.xml +/modules.xml +/SpringCloudLearning.iml +/vcs.xml +/libraries/ +/.name +/encodings.xml +/compiler.xml +uiDesigner.xml +inspectionProfiles \ No newline at end of file diff --git a/chapter10/eureka-server/src/main/resources/application-peer1.yml b/chapter10/eureka-server/src/main/resources/application-peer1.yml index 58394c6540a09c096388c5e680ec486a2f99b3f5..614da65ff1fbe2cce0092978ae163097d41afb26 100755 --- a/chapter10/eureka-server/src/main/resources/application-peer1.yml +++ b/chapter10/eureka-server/src/main/resources/application-peer1.yml @@ -1,8 +1,8 @@ server: port: 8761 -spring: - profiles: peer1 +#spring: +# profiles: peer1 eureka: instance: hostname: peer1 diff --git a/chapter10/eureka-server/src/main/resources/application-peer2.yml b/chapter10/eureka-server/src/main/resources/application-peer2.yml index bc1c565be7348a88d1d81084a03246e8f865157a..cf164244381fd186792a6f00d817f0b5b43fda84 100755 --- a/chapter10/eureka-server/src/main/resources/application-peer2.yml +++ b/chapter10/eureka-server/src/main/resources/application-peer2.yml @@ -2,8 +2,8 @@ server: port: 8769 -spring: - profiles: peer2 +#spring: +# profiles: peer2 eureka: instance: hostname: peer2 diff --git a/chapter10/eureka-server/src/main/resources/application.yml b/chapter10/eureka-server/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..e887b19d0c5b16d1c37d313e5e9e656657afbb10 --- /dev/null +++ b/chapter10/eureka-server/src/main/resources/application.yml @@ -0,0 +1,3 @@ +spring: + profiles: + active: peer1 \ No newline at end of file diff --git a/chapter10/service-hi/src/main/resources/bootstrap.yml b/chapter10/service-hi/src/main/resources/bootstrap.yml index 11280823df14f5e9da9865a75767faf8452d09e9..8a3580369e4cd05e96a1531b177306b415ce56ed 100755 --- a/chapter10/service-hi/src/main/resources/bootstrap.yml +++ b/chapter10/service-hi/src/main/resources/bootstrap.yml @@ -1,7 +1,7 @@ eureka: client: serviceUrl: - defaultZone: http://peer2:8769/eureka/,http://peer1:8761/eureka/ + defaultZone: http://peer1:8761/eureka/,http://peer2:8769/eureka/ server: port: 8762 spring: diff --git a/chapter11/eureka-server/src/main/docker/Dockerfile b/chapter11/eureka-server/src/main/docker/Dockerfile index 687de4d0e738eeb7e580b445b4e68faea8e197bb..416b4f7acc0db671e59d0e1e59a6dbd4d1f0e488 100755 --- a/chapter11/eureka-server/src/main/docker/Dockerfile +++ b/chapter11/eureka-server/src/main/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM frolvlad/alpine-oraclejdk8:slim +FROM openjdk:8u242-slim VOLUME /tmp ADD eureka-server-0.0.1-SNAPSHOT.jar app.jar #RUN bash -c 'touch /app.jar' diff --git a/chapter11/service-hi/src/main/docker/Dockerfile b/chapter11/service-hi/src/main/docker/Dockerfile index 92fbb35c43c5b8ea57d24e20dd4e2421ea87bb3b..ef8076f469a3fa9f71180193e8f0e6bc2d37d30e 100755 --- a/chapter11/service-hi/src/main/docker/Dockerfile +++ b/chapter11/service-hi/src/main/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM frolvlad/alpine-oraclejdk8:slim +FROM openjdk:8u242-slim VOLUME /tmp ADD service-hi-0.0.1-SNAPSHOT.jar app.jar #RUN bash -c 'touch /app.jar' diff --git a/chapter6/config-server/src/main/resources/application.properties b/chapter6/config-server/src/main/resources/application.properties index 21a87687e389ccc9ce4ac3134612fdbb8d84d80d..1821cf1dc59d9ff01eae0fc3f955b2dee073b459 100755 --- a/chapter6/config-server/src/main/resources/application.properties +++ b/chapter6/config-server/src/main/resources/application.properties @@ -2,7 +2,7 @@ spring.application.name=config-server server.port=8888 -spring.cloud.config.server.git.uri=https://github.com/forezp/SpringcloudConfig/ +spring.cloud.config.server.git.uri=https://gitee.com/yanghaojie002/SpringcloudConfig/ spring.cloud.config.server.git.searchPaths=respo spring.cloud.config.label=master spring.cloud.config.server.git.username= diff --git a/chapter8/config-server/src/main/resources/application.properties b/chapter8/config-server/src/main/resources/application.properties index e3baefd3101da7858cf465bfb10ebe43eff36e41..2fbcfb84fed3a4eeabb222f5b0ab60e92e70f67e 100755 --- a/chapter8/config-server/src/main/resources/application.properties +++ b/chapter8/config-server/src/main/resources/application.properties @@ -2,10 +2,10 @@ spring.application.name=config-server server.port=8888 -spring.cloud.config.server.git.uri=https://github.com/forezp/SpringcloudConfig/ +spring.cloud.config.server.git.uri=https://gitee.com/yanghaojie002/SpringcloudConfig/ spring.cloud.config.server.git.searchPaths=respo spring.cloud.config.label=master -spring.cloud.config.server.git.username=your username -spring.cloud.config.server.git.password=your password +spring.cloud.config.server.git.username= +spring.cloud.config.server.git.password= eureka.client.serviceUrl.defaultZone=http://localhost:8889/eureka/ \ No newline at end of file diff --git a/sc-f-boot-admin-cloud/admin-server/src/main/resources/application.yml b/sc-f-boot-admin-cloud/admin-server/src/main/resources/application.yml index a412b4e87d25b0f1cb00510f564084ae9d8f1efc..5c118753072e23988a62ad6fdf69ba12a4b81080 100644 --- a/sc-f-boot-admin-cloud/admin-server/src/main/resources/application.yml +++ b/sc-f-boot-admin-cloud/admin-server/src/main/resources/application.yml @@ -30,7 +30,8 @@ management: spring.mail.host: smtp.163.com -spring.mail.username: miles02 -spring.mail.password: -spring.boot.admin.notify.mail.to: 124746406@qq.com +spring.mail.username: 13486032976@163.com +# 这里的密码不是登录密码,而是授权码 +spring.mail.password: qsx741olm +spring.boot.admin.notify.mail.to: 1186827476@qq.com diff --git a/sc-f-gateway-filter/.gitignore b/sc-f-gateway-filter/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..797b705f6e8ff19cb087263cb82fdffc7b74433c --- /dev/null +++ b/sc-f-gateway-filter/.gitignore @@ -0,0 +1 @@ +*.iml \ No newline at end of file diff --git a/sc-f-gateway-filter/sc-f-gateway-filter.iml b/sc-f-gateway-filter/sc-f-gateway-filter.iml deleted file mode 100644 index 3b4b5717a06f90e1eeba50c5c20059a34bb0e98d..0000000000000000000000000000000000000000 --- a/sc-f-gateway-filter/sc-f-gateway-filter.iml +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sc-f-gateway-filter/src/main/java/gateway/Application.java b/sc-f-gateway-filter/src/main/java/gateway/Application.java index 71835749530b99095e027c73c3df700c9671fc44..137ac6a898dffb32a54ab9dfa19b13ce5ad0ced4 100644 --- a/sc-f-gateway-filter/src/main/java/gateway/Application.java +++ b/sc-f-gateway-filter/src/main/java/gateway/Application.java @@ -3,6 +3,8 @@ package gateway; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; import org.springframework.context.annotation.Bean; import org.springframework.web.bind.annotation.RestController; @@ -15,30 +17,30 @@ public class Application { } -// @Bean -// public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) { -// -// return builder.routes() -// .route(r -> r.path("/customer/**") -// .filters(f -> f.filter(new RequestTimeFilter()) -// .addResponseHeader("X-Response-Default-Foo", "Default-Bar")) -// .uri("http://httpbin.org:80/get") -// .order(0) -// .id("customer_filter_router") -// ) -// .build(); -// -// } - -// @Bean -// public TokenFilter tokenFilter(){ -// return new TokenFilter(); -// } + @Bean + public RouteLocator customerRouteLocator(RouteLocatorBuilder builder) { + + return builder.routes() + .route(r -> r.path("/customer/**") + .filters(f -> f.filter(new RequestTimeFilter()) + .addResponseHeader("X-Response-Default-Foo", "Default-Bar")) + .uri("http://httpbin.org:80/get") + .order(0) + .id("customer_filter_router") + ) + .build(); + } @Bean - public RequestTimeGatewayFilterFactory elapsedGatewayFilterFactory() { - return new RequestTimeGatewayFilterFactory(); + public TokenFilter tokenFilter(){ + return new TokenFilter(); } + + +// @Bean +// public RequestTimeGatewayFilterFactory elapsedGatewayFilterFactory() { +// return new RequestTimeGatewayFilterFactory(); +// } } diff --git a/sc-f-gateway-filter/src/main/java/gateway/RequestTimeGatewayFilterFactory.java b/sc-f-gateway-filter/src/main/java/gateway/RequestTimeGatewayFilterFactory.java index af374ebc7b57cfc37004b84a39d3858eada9f56e..a1a7a002ee37ef879347d60a710f10d04e3f75bf 100644 --- a/sc-f-gateway-filter/src/main/java/gateway/RequestTimeGatewayFilterFactory.java +++ b/sc-f-gateway-filter/src/main/java/gateway/RequestTimeGatewayFilterFactory.java @@ -1,74 +1,74 @@ -package gateway; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.cloud.gateway.filter.GatewayFilter; -import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; -import reactor.core.publisher.Mono; - -import java.util.Arrays; -import java.util.List; - -/** - * Email miles02@163.com - * - * @author fangzhipeng - * create 2018-11-16 - **/ -public class RequestTimeGatewayFilterFactory extends AbstractGatewayFilterFactory { - - - private static final Log log = LogFactory.getLog(GatewayFilter.class); - private static final String REQUEST_TIME_BEGIN = "requestTimeBegin"; - private static final String KEY = "withParams"; - - @Override - public List shortcutFieldOrder() { - return Arrays.asList(KEY); - } - - public RequestTimeGatewayFilterFactory() { - super(Config.class); - } - - @Override - public GatewayFilter apply(Config config) { - return (exchange, chain) -> { - exchange.getAttributes().put(REQUEST_TIME_BEGIN, System.currentTimeMillis()); - return chain.filter(exchange).then( - Mono.fromRunnable(() -> { - Long startTime = exchange.getAttribute(REQUEST_TIME_BEGIN); - if (startTime != null) { - StringBuilder sb = new StringBuilder(exchange.getRequest().getURI().getRawPath()) - .append(": ") - .append(System.currentTimeMillis() - startTime) - .append("ms"); - if (config.isWithParams()) { - sb.append(" params:").append(exchange.getRequest().getQueryParams()); - } - log.info(sb.toString()); - } - }) - ); - }; - } - - - - - - - public static class Config { - - private boolean withParams; - - public boolean isWithParams() { - return withParams; - } - - public void setWithParams(boolean withParams) { - this.withParams = withParams; - } - - } -} +//package gateway; +// +//import org.apache.commons.logging.Log; +//import org.apache.commons.logging.LogFactory; +//import org.springframework.cloud.gateway.filter.GatewayFilter; +//import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; +//import reactor.core.publisher.Mono; +// +//import java.util.Arrays; +//import java.util.List; +// +///** +// * Email miles02@163.com +// * +// * @author fangzhipeng +// * create 2018-11-16 +// **/ +//public class RequestTimeGatewayFilterFactory extends AbstractGatewayFilterFactory { +// +// +// private static final Log log = LogFactory.getLog(GatewayFilter.class); +// private static final String REQUEST_TIME_BEGIN = "requestTimeBegin"; +// private static final String KEY = "withParams"; +// +// @Override +// public List shortcutFieldOrder() { +// return Arrays.asList(KEY); +// } +// +// public RequestTimeGatewayFilterFactory() { +// super(Config.class); +// } +// +// @Override +// public GatewayFilter apply(Config config) { +// return (exchange, chain) -> { +// exchange.getAttributes().put(REQUEST_TIME_BEGIN, System.currentTimeMillis()); +// return chain.filter(exchange).then( +// Mono.fromRunnable(() -> { +// Long startTime = exchange.getAttribute(REQUEST_TIME_BEGIN); +// if (startTime != null) { +// StringBuilder sb = new StringBuilder(exchange.getRequest().getURI().getRawPath()) +// .append(": ") +// .append(System.currentTimeMillis() - startTime) +// .append("ms"); +// if (config.isWithParams()) { +// sb.append(" params:").append(exchange.getRequest().getQueryParams()); +// } +// log.info(sb.toString()); +// } +// }) +// ); +// }; +// } +// +// +// +// +// +// +// public static class Config { +// +// private boolean withParams; +// +// public boolean isWithParams() { +// return withParams; +// } +// +// public void setWithParams(boolean withParams) { +// this.withParams = withParams; +// } +// +// } +//} diff --git a/sc-f-gateway-filter/src/main/java/org/springframework/cloud/gateway/filter/factory/AbstractChangeRequestUriGatewayFilterFactory.java b/sc-f-gateway-filter/src/main/java/org/springframework/cloud/gateway/filter/factory/AbstractChangeRequestUriGatewayFilterFactory.java index 74928f56777f031af68216a2b2d2e29c13c935d6..e644454adc927ae072e5f2b28fa93a9bbcbced5f 100644 --- a/sc-f-gateway-filter/src/main/java/org/springframework/cloud/gateway/filter/factory/AbstractChangeRequestUriGatewayFilterFactory.java +++ b/sc-f-gateway-filter/src/main/java/org/springframework/cloud/gateway/filter/factory/AbstractChangeRequestUriGatewayFilterFactory.java @@ -1,10 +1,10 @@ -package org.springframework.cloud.gateway.filter.factory; - -/** - * Email miles02@163.com - * - * @author fangzhipeng - * create 2018-12-04 - **/ -public abstract class AbstractChangeRequestUriGatewayFilterFactory extends AbstractGatewayFilterFactory { -} +//package org.springframework.cloud.gateway.filter.factory; +// +///** +// * Email miles02@163.com +// * +// * @author fangzhipeng +// * create 2018-12-04 +// **/ +//public abstract class AbstractChangeRequestUriGatewayFilterFactory extends AbstractGatewayFilterFactory { +//} diff --git a/sc-f-gateway-filter/src/main/resources/application.yml b/sc-f-gateway-filter/src/main/resources/application.yml index 144b15c2c086482514276ec9d553677925254426..37a6c74fbbf1ce3f537be261c02c89169e709113 100644 --- a/sc-f-gateway-filter/src/main/resources/application.yml +++ b/sc-f-gateway-filter/src/main/resources/application.yml @@ -56,3 +56,16 @@ spring: predicates: - After=2017-01-20T17:42:47.789-07:00[America/Denver] profiles: request_time_route + +--- +spring: + cloud: + gateway: + routes: + - id: elapse_route + uri: http://httpbin.org:80/get + filters: + - RequestTime=false + predicates: + - After=2017-01-20T17:42:47.789-07:00[America/Denver] + profiles: elapse_route \ No newline at end of file diff --git a/sc-f-gateway-first-sight/.gitignore b/sc-f-gateway-first-sight/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..797b705f6e8ff19cb087263cb82fdffc7b74433c --- /dev/null +++ b/sc-f-gateway-first-sight/.gitignore @@ -0,0 +1 @@ +*.iml \ No newline at end of file diff --git a/sc-f-gateway-first-sight/target/classes/gateway/Application.class b/sc-f-gateway-first-sight/target/classes/gateway/Application.class deleted file mode 100644 index fd138704a8749effe5ef3e9ca7500706188a8bfc..0000000000000000000000000000000000000000 Binary files a/sc-f-gateway-first-sight/target/classes/gateway/Application.class and /dev/null differ diff --git a/sc-f-gateway-limiter/.gitignore b/sc-f-gateway-limiter/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..dc48b22fcf39363aabe1371a0336b543c5a49690 --- /dev/null +++ b/sc-f-gateway-limiter/.gitignore @@ -0,0 +1,2 @@ +*.iml +target \ No newline at end of file diff --git a/sc-f-gateway-limiter/pom.xml b/sc-f-gateway-limiter/pom.xml index f30a00665ecd2e35a9da31d2ffdb508d81940ffd..35219094adf8d5880dc475f84c91722c13daaf11 100644 --- a/sc-f-gateway-limiter/pom.xml +++ b/sc-f-gateway-limiter/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.forezp - sc-f-gateway-filter + sc-f-gateway-limiter 0.1.0 diff --git a/sc-f-gateway-limiter/sc-f-gateway-filter.iml b/sc-f-gateway-limiter/sc-f-gateway-filter.iml deleted file mode 100644 index d5ad85a5883eec9beeb711a4a24b452600644c3e..0000000000000000000000000000000000000000 --- a/sc-f-gateway-limiter/sc-f-gateway-filter.iml +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sc-f-gateway-limiter/src/main/resources/application.yml b/sc-f-gateway-limiter/src/main/resources/application.yml index 3b536b2c4c7fafd904bcd7af5d116767e677fe37..a6c37979f352c065f6d16cc058536f5eb96dbf04 100644 --- a/sc-f-gateway-limiter/src/main/resources/application.yml +++ b/sc-f-gateway-limiter/src/main/resources/application.yml @@ -13,7 +13,7 @@ spring: args: key-resolver: '#{@hostAddrKeyResolver}' redis-rate-limiter.replenishRate: 1 - redis-rate-limiter.burstCapacity: 1 + redis-rate-limiter.burstCapacity: 3 application: name: gateway-limiter redis: diff --git a/sc-f-gateway-limiter/target/classes/application.yml b/sc-f-gateway-limiter/target/classes/application.yml deleted file mode 100644 index 3b536b2c4c7fafd904bcd7af5d116767e677fe37..0000000000000000000000000000000000000000 --- a/sc-f-gateway-limiter/target/classes/application.yml +++ /dev/null @@ -1,25 +0,0 @@ -server: - port: 8081 -spring: - cloud: - gateway: - routes: - - id: limit_route - uri: http://httpbin.org:80/get - predicates: - - After=2017-01-20T17:42:47.789-07:00[America/Denver] - filters: - - name: RequestRateLimiter - args: - key-resolver: '#{@hostAddrKeyResolver}' - redis-rate-limiter.replenishRate: 1 - redis-rate-limiter.burstCapacity: 1 - application: - name: gateway-limiter - redis: - host: localhost - port: 6379 - database: 0 - - - diff --git a/sc-f-gateway-limiter/target/classes/gateway/Application.class b/sc-f-gateway-limiter/target/classes/gateway/Application.class deleted file mode 100644 index 08584493cb87b8470bb42d81e1410519d0959080..0000000000000000000000000000000000000000 Binary files a/sc-f-gateway-limiter/target/classes/gateway/Application.class and /dev/null differ diff --git a/sc-f-gateway-limiter/target/classes/gateway/HostAddrKeyResolver.class b/sc-f-gateway-limiter/target/classes/gateway/HostAddrKeyResolver.class deleted file mode 100644 index c086a34278af7c12be0f1d08f61b87800b229efd..0000000000000000000000000000000000000000 Binary files a/sc-f-gateway-limiter/target/classes/gateway/HostAddrKeyResolver.class and /dev/null differ diff --git a/sc-f-gateway-limiter/target/classes/gateway/UriKeyResolver.class b/sc-f-gateway-limiter/target/classes/gateway/UriKeyResolver.class deleted file mode 100644 index 84d074ba4df1a3106504c31abb23b4c1e1e6be9c..0000000000000000000000000000000000000000 Binary files a/sc-f-gateway-limiter/target/classes/gateway/UriKeyResolver.class and /dev/null differ diff --git a/sc-f-gateway-predicate/.gitignore b/sc-f-gateway-predicate/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..dc48b22fcf39363aabe1371a0336b543c5a49690 --- /dev/null +++ b/sc-f-gateway-predicate/.gitignore @@ -0,0 +1,2 @@ +*.iml +target \ No newline at end of file diff --git a/sc-f-gateway-predicate/target/classes/application.yml b/sc-f-gateway-predicate/target/classes/application.yml deleted file mode 100644 index 99fd3fb03fff676290b47130e69fd1cd17d6933d..0000000000000000000000000000000000000000 --- a/sc-f-gateway-predicate/target/classes/application.yml +++ /dev/null @@ -1,84 +0,0 @@ -server: - port: 8081 -spring: - profiles: - active: query_route - ---- -spring: - cloud: - gateway: - routes: - - id: after_route - uri: http://httpbin.org:80/get - predicates: - - After=2017-01-20T17:42:47.789-07:00[America/Denver] - profiles: after_route - ---- -spring: - cloud: - gateway: - routes: - - id: header_route - uri: http://httpbin.org:80/get - predicates: - - Header=X-Request-Id, \d+ - profiles: header_route - ---- -spring: - cloud: - gateway: - routes: - - id: cookie_route - uri: http://httpbin.org:80/get - predicates: - - Cookie=name, forezp - profiles: cookie_route - ---- -spring: - cloud: - gateway: - routes: - - id: host_route - uri: http://httpbin.org:80/get - predicates: - - Host=**.fangzhipeng.com - profiles: host_route - - ---- -spring: - cloud: - gateway: - routes: - - id: method_route - uri: http://httpbin.org:80/get - predicates: - - Method=GET - profiles: method_route - ---- -spring: - cloud: - gateway: - routes: - - id: path_route - uri: http://httpbin.org:80/get - predicates: - - Path=/foo/{segment} - profiles: path_route - ---- - -spring: - cloud: - gateway: - routes: - - id: query_route - uri: http://httpbin.org:80/get - predicates: - - Query=foo, ba. - profiles: query_route \ No newline at end of file diff --git a/sc-f-gateway-predicate/target/classes/gateway/Application.class b/sc-f-gateway-predicate/target/classes/gateway/Application.class deleted file mode 100644 index 99f5bc566a6d8d2f4e13809a3727a48d8e3f2f2c..0000000000000000000000000000000000000000 Binary files a/sc-f-gateway-predicate/target/classes/gateway/Application.class and /dev/null differ diff --git a/springcloud-alibaba/nacos-config/nacos-consumer/pom.xml b/springcloud-alibaba/nacos-config/nacos-consumer/pom.xml index 70fe5b0e9343be67aa7da8b7fc65ef48d925fda7..a98eed9b5e6dafe7cb89cce732291ddd94cf3ba2 100644 --- a/springcloud-alibaba/nacos-config/nacos-consumer/pom.xml +++ b/springcloud-alibaba/nacos-config/nacos-consumer/pom.xml @@ -41,7 +41,7 @@ org.springframework.cloud - spring-cloud-starter-ribbon + spring-cloud-starter-netflix-ribbon diff --git a/springcloud-alibaba/nacos-discovery-sentinel/.gitignore b/springcloud-alibaba/nacos-discovery-sentinel/.gitignore index 153c9335ebd71e66178495914ea0d42e367b909c..4a4530315ea4296865599ec8138db3f8f3366353 100644 --- a/springcloud-alibaba/nacos-discovery-sentinel/.gitignore +++ b/springcloud-alibaba/nacos-discovery-sentinel/.gitignore @@ -1,4 +1,3 @@ -HELP.md /target/ !.mvn/wrapper/maven-wrapper.jar diff --git a/springcloud-alibaba/nacos-discovery-sentinel/README.md b/springcloud-alibaba/nacos-discovery-sentinel/README.md new file mode 100644 index 0000000000000000000000000000000000000000..416bbe1016821d9e5ab1375305ffa2a8cc42308b --- /dev/null +++ b/springcloud-alibaba/nacos-discovery-sentinel/README.md @@ -0,0 +1,18 @@ +# Getting Started +## spring cloud alibaba教程:Sentinel的使用(限流,熔断降级,比Hystrix更细粒度) +https://note.wiz.cn/web/web?dc=7b1b08ac-e891-4c37-9114-518dbf7fc935&kb=&cmd=km%2C + +### Reference Documentation +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.2.5.RELEASE/maven-plugin/) +* [Spring Web](https://docs.spring.io/spring-boot/docs/2.2.5.RELEASE/reference/htmlsingle/#boot-features-developing-web-applications) + +### Guides +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/) + diff --git a/springcloud-alibaba/nacos-discovery-sentinel/nacos-consumer/pom.xml b/springcloud-alibaba/nacos-discovery-sentinel/nacos-consumer/pom.xml index 523952d194d65da2f37c77a50b10dcb506610ae5..e6347c030d62461dba8309c73d46f371f8ffff09 100644 --- a/springcloud-alibaba/nacos-discovery-sentinel/nacos-consumer/pom.xml +++ b/springcloud-alibaba/nacos-discovery-sentinel/nacos-consumer/pom.xml @@ -41,7 +41,7 @@ org.springframework.cloud - spring-cloud-starter-ribbon + spring-cloud-starter-netflix-ribbon diff --git a/springcloud-alibaba/nacos-discovery-sentinel/nacos-provider/pom.xml b/springcloud-alibaba/nacos-discovery-sentinel/nacos-provider/pom.xml index 7155d0bafcc33c6e57a91d8f5938139a9d517822..e5767e51ab8c35979bc77e0be34865d4031a07c1 100644 --- a/springcloud-alibaba/nacos-discovery-sentinel/nacos-provider/pom.xml +++ b/springcloud-alibaba/nacos-discovery-sentinel/nacos-provider/pom.xml @@ -44,6 +44,11 @@ spring-cloud-starter-alibaba-sentinel 0.9.0.RELEASE + + org.projectlombok + lombok + 1.18.12 + diff --git a/springcloud-alibaba/nacos-discovery-sentinel/nacos-provider/src/main/java/com/forezp/web/ProviderController.java b/springcloud-alibaba/nacos-discovery-sentinel/nacos-provider/src/main/java/com/forezp/web/ProviderController.java index 44d7e8d389d32cb41c73aacd9a312e7c5fdde170..9c7b663b7cb798c2c3d8904cede37988ba917514 100644 --- a/springcloud-alibaba/nacos-discovery-sentinel/nacos-provider/src/main/java/com/forezp/web/ProviderController.java +++ b/springcloud-alibaba/nacos-discovery-sentinel/nacos-provider/src/main/java/com/forezp/web/ProviderController.java @@ -1,6 +1,8 @@ package com.forezp.web; import com.alibaba.csp.sentinel.annotation.SentinelResource; +import com.alibaba.csp.sentinel.slots.block.BlockException; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -17,6 +19,7 @@ import java.util.List; */ @RestController +@Slf4j public class ProviderController { Logger logger= LoggerFactory.getLogger(ProviderController.class); @@ -27,12 +30,27 @@ public class ProviderController { @GetMapping("/hi") - @SentinelResource("hi") + @SentinelResource(value = "hi",blockHandler = "blockHandler",fallback = "fallbackHandler") public String hi(@RequestParam(value = "name",defaultValue = "forezp",required = false)String name){ - + if (name.equals("123")){ + throw new RuntimeException("发生异常"); + } return "hi "+name; } + // 限流降级处理 + public String blockHandler(String name, BlockException ex) { + log.error( "blockHandler:" + name, ex); + System.out.println("blockHandler:" + name); + return "blockHandler"; + } + + // 熔断降级处理 + public String fallbackHandler(String name) { + log.error("fallbackHandler:" + name); + System.out.println("fallbackHandler:" + name); + return "fallback"; + } @GetMapping("/services") public String getServices(){ diff --git a/springcloud-alibaba/nacos-discovery/nacos-consumer/pom.xml b/springcloud-alibaba/nacos-discovery/nacos-consumer/pom.xml index 70fe5b0e9343be67aa7da8b7fc65ef48d925fda7..a98eed9b5e6dafe7cb89cce732291ddd94cf3ba2 100644 --- a/springcloud-alibaba/nacos-discovery/nacos-consumer/pom.xml +++ b/springcloud-alibaba/nacos-discovery/nacos-consumer/pom.xml @@ -41,7 +41,7 @@ org.springframework.cloud - spring-cloud-starter-ribbon + spring-cloud-starter-netflix-ribbon