diff --git a/README.md b/README.md
index bd401118..1706a329 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,15 @@
# microservices-platform
+[](https://www.apache.org/licenses/LICENSE-2.0.html)
+
## 如果您觉得有帮助,请点右上角 "Star" 支持一下谢谢
[TOC]
## 1. 项目介绍
-* 技术交流群 [250883130](http://shang.qq.com/wpa/qunwpa?idkey=17544199255998bda0d938fb72b08d076c40c52c9904520b76eb5eb0585da71e)
+* 技术交流群 [250883130](http://shang.qq.com/wpa/qunwpa?idkey=17544199255998bda0d938fb72b08d076c40c52c9904520b76eb5eb0585da71e)
+
* **详细在线文档** [点击查看](https://www.kancloud.cn/zlt2000/microservices-platform/919412)
* 前后端分离的企业级微服务架构
* 基于`Spring Boot 2.0.X`、`Spring Cloud Finchley`和`Spring Cloud Alibaba`
@@ -24,17 +27,24 @@
* 支持手机号加密码登录
* 支持openId登录
* 支持第三方系统单点登录
+
* **分布式系统基础支撑**
* 服务注册发现、路由与负载均衡
* 服务降级与熔断
- * 服务调用链监控
+ * 服务限流(url/方法级别)
* 统一配置中心
* 统一日志中心
* 统一分布式缓存操作类、cacheManager配置扩展
* 分布式锁
* 分布式任务调度器
+* **系统监控功能**
+ * 服务调用链监控
* 应用监控(应用健康、JVM、内存、线程)
+ * 错误日志查询
* 慢查询SQL监控
+ * 应用吞吐量监控(qps、rt)
+ * 服务降级、熔断监控
+ * 服务限流监控
* **业务基础功能支撑**
* 高性能方法级幂等性支持
* RBAC权限管理,实现细粒度控制(方法、url级别)
@@ -59,10 +69,11 @@ central-platform -- 父项目,公共依赖
│ │ ├─zlt-common-spring-boot-starter -- 封装通用操作逻辑
│ │ ├─zlt-db-spring-boot-starter -- 封装数据库通用操作逻辑
│ │ ├─zlt-log-spring-boot-starter -- 封装log通用操作逻辑
+│ │ ├─zlt-mq-spring-boot-starter -- 封装mq通用操作逻辑
│ │ ├─zlt-redis-spring-boot-starter -- 封装Redis通用操作逻辑
│ │ ├─zlt-ribbon-spring-boot-starter -- 封装Ribbon和Feign的通用操作逻辑
+│ │ ├─zlt-sentinel-spring-boot-starter -- 封装Sentinel的通用操作逻辑
│ │ ├─zlt-swagger2-spring-boot-starter -- 封装Swagger通用操作逻辑
-│ │ ├─zlt-mq-spring-boot-starter -- 封装mq通用操作逻辑
│ ├─zlt-config -- 配置中心
│ ├─zlt-doc -- 项目文档
│ ├─zlt-gateway -- api网关一级工程
diff --git a/pom.xml b/pom.xml
index f9029577..0279a0f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -111,6 +111,11 @@
zlt-auth-client-spring-boot-starter
${project.version}
+
+ com.zlt
+ zlt-sentinel-spring-boot-starter
+ ${project.version}
+
com.zlt
zlt-config
diff --git a/zlt-business/file-center/pom.xml b/zlt-business/file-center/pom.xml
index e2b48e67..ec048440 100644
--- a/zlt-business/file-center/pom.xml
+++ b/zlt-business/file-center/pom.xml
@@ -10,6 +10,10 @@
文件中心
+
+ com.zlt
+ zlt-config
+
com.zlt
zlt-common-spring-boot-starter
@@ -24,7 +28,7 @@
com.zlt
- zlt-config
+ zlt-sentinel-spring-boot-starter
diff --git a/zlt-business/user-center/pom.xml b/zlt-business/user-center/pom.xml
index 5642790a..97e61cd9 100644
--- a/zlt-business/user-center/pom.xml
+++ b/zlt-business/user-center/pom.xml
@@ -10,6 +10,10 @@
用户中心
+
+ com.zlt
+ zlt-config
+
com.zlt
zlt-common-spring-boot-starter
@@ -26,15 +30,15 @@
com.zlt
zlt-ribbon-spring-boot-starter
+
+ com.zlt
+ zlt-sentinel-spring-boot-starter
+
com.zlt
zlt-swagger2-spring-boot-starter
-
- com.zlt
- zlt-config
-
org.springframework.cloud
diff --git a/zlt-business/user-center/src/main/resources/application.yml b/zlt-business/user-center/src/main/resources/application.yml
index 11619382..0e6a2767 100644
--- a/zlt-business/user-center/src/main/resources/application.yml
+++ b/zlt-business/user-center/src/main/resources/application.yml
@@ -9,7 +9,7 @@ spring:
host: ${zlt.redis.host}
port: ${zlt.redis.port}
timeout: ${zlt.redis.timeout}
-
+
mybatis-plus:
mapper-locations: classpath:/mapper/*Mapper.xml
#实体扫描,多个package用逗号或者分号分隔
@@ -30,4 +30,4 @@ zlt:
- key: menu
second: 600
- key: user
- second: 1800
\ No newline at end of file
+ second: 1800
diff --git a/zlt-commons/pom.xml b/zlt-commons/pom.xml
index b09554a7..b1deaf1f 100644
--- a/zlt-commons/pom.xml
+++ b/zlt-commons/pom.xml
@@ -19,5 +19,6 @@
zlt-ribbon-spring-boot-starter
zlt-auth-client-spring-boot-starter
zlt-mq-spring-boot-starter
+ zlt-sentinel-spring-boot-starter
\ No newline at end of file
diff --git a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java
index 71ebe540..00f7166a 100644
--- a/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java
+++ b/zlt-commons/zlt-redis-spring-boot-starter/src/main/java/com/central/common/redis/RedisAutoConfigure.java
@@ -12,7 +12,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
@@ -21,7 +20,6 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.*;
import java.time.Duration;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -31,7 +29,6 @@ import java.util.Map;
* @author zlt
* @date 2018/11/6 11:02
*/
-@Configuration
@ConditionalOnClass(RedisRepository.class)
@EnableConfigurationProperties({RedisProperties.class, CacheManagerProperties.class})
@EnableCaching
diff --git a/zlt-commons/zlt-ribbon-spring-boot-starter/pom.xml b/zlt-commons/zlt-ribbon-spring-boot-starter/pom.xml
index bdc9a9f6..4d6a8369 100644
--- a/zlt-commons/zlt-ribbon-spring-boot-starter/pom.xml
+++ b/zlt-commons/zlt-ribbon-spring-boot-starter/pom.xml
@@ -19,35 +19,14 @@
org.springframework.cloud
spring-cloud-starter-openfeign
-
-
- HdrHistogram
- org.hdrhistogram
-
-
org.springframework.cloud
spring-cloud-starter-netflix-ribbon
-
- org.springframework.cloud
- spring-cloud-starter-netflix-hystrix
-
-
- HdrHistogram
- org.hdrhistogram
-
-
-
org.apache.httpcomponents
httpclient
-
- org.springframework.boot
- spring-boot-starter-web
- provided
-
diff --git a/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/FeignAutoConfigure.java b/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/FeignAutoConfigure.java
index 3bd8b913..afa6bbbd 100644
--- a/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/FeignAutoConfigure.java
+++ b/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/FeignAutoConfigure.java
@@ -2,7 +2,6 @@ package com.central.common.ribbon;
import feign.Logger;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
/**
* Feign统一配置
@@ -10,7 +9,6 @@ import org.springframework.context.annotation.Configuration;
* @author zlt
* @date 2018/9/18 14:04
*/
-@Configuration
public class FeignAutoConfigure {
/**
diff --git a/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/RestTemplateAutoConfigure.java b/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/RestTemplateAutoConfigure.java
index 6209c1a3..c96fb859 100644
--- a/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/RestTemplateAutoConfigure.java
+++ b/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/RestTemplateAutoConfigure.java
@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@@ -24,7 +23,6 @@ import org.springframework.web.client.RestTemplate;
* @author zlt
* @date 2018/11/17
*/
-@Configuration
@EnableConfigurationProperties(RestTemplateProperties.class)
public class RestTemplateAutoConfigure {
@Autowired
diff --git a/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/RibbonAutoConfigure.java b/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/RibbonAutoConfigure.java
index 84810ea8..be4ec44b 100644
--- a/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/RibbonAutoConfigure.java
+++ b/zlt-commons/zlt-ribbon-spring-boot-starter/src/main/java/com/central/common/ribbon/RibbonAutoConfigure.java
@@ -2,10 +2,8 @@ package com.central.common.ribbon;
import com.central.common.ribbon.config.RestTemplateProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.ribbon.DefaultPropertiesFactory;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
/**
* Ribbon扩展配置类
@@ -13,11 +11,8 @@ import org.springframework.context.annotation.Configuration;
* @author zlt
* @date 2018/11/17 9:24
*/
-@Configuration
-@EnableCircuitBreaker
@EnableConfigurationProperties(RestTemplateProperties.class)
public class RibbonAutoConfigure {
-
@Bean
public DefaultPropertiesFactory defaultPropertiesFactory() {
return new DefaultPropertiesFactory();
diff --git a/zlt-commons/zlt-sentinel-spring-boot-starter/.gitignore b/zlt-commons/zlt-sentinel-spring-boot-starter/.gitignore
new file mode 100644
index 00000000..9c942580
--- /dev/null
+++ b/zlt-commons/zlt-sentinel-spring-boot-starter/.gitignore
@@ -0,0 +1,2 @@
+/target/
+*.iml
\ No newline at end of file
diff --git a/zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml b/zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml
new file mode 100644
index 00000000..68c3c57e
--- /dev/null
+++ b/zlt-commons/zlt-sentinel-spring-boot-starter/pom.xml
@@ -0,0 +1,38 @@
+
+
+
+ com.zlt
+ zlt-commons
+ 1.0.0
+
+ 4.0.0
+ jar
+ zlt-sentinel-spring-boot-starter
+ 服务降级、熔断和限流通用组件
+
+
+ com.zlt
+ zlt-common-spring-boot-starter
+
+
+ org.springframework.cloud
+ spring-cloud-starter-alibaba-sentinel
+
+
+ com.alibaba.csp
+ sentinel-datasource-nacos
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+ provided
+
+
+
diff --git a/zlt-commons/zlt-sentinel-spring-boot-starter/src/main/java/com/central/sentinel/config/SentinelAutoConfigure.java b/zlt-commons/zlt-sentinel-spring-boot-starter/src/main/java/com/central/sentinel/config/SentinelAutoConfigure.java
new file mode 100644
index 00000000..1ff5bc5e
--- /dev/null
+++ b/zlt-commons/zlt-sentinel-spring-boot-starter/src/main/java/com/central/sentinel/config/SentinelAutoConfigure.java
@@ -0,0 +1,34 @@
+package com.central.sentinel.config;
+
+import cn.hutool.json.JSONUtil;
+import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
+import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
+import com.alibaba.csp.sentinel.slots.block.BlockException;
+import com.central.common.model.Result;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Sentinel配置类
+ *
+ * @author zlt
+ * @date 2019/1/22
+ */
+public class SentinelAutoConfigure {
+ public SentinelAutoConfigure() {
+ WebCallbackManager.setUrlBlockHandler(new CustomUrlBlockHandler());
+ }
+
+ /**
+ * 限流、熔断统一处理类
+ */
+ public class CustomUrlBlockHandler implements UrlBlockHandler {
+ @Override
+ public void blocked(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws IOException {
+ Result result = Result.failed("flow-limiting");
+ httpServletResponse.getWriter().print(JSONUtil.toJsonStr(result));
+ }
+ }
+}
diff --git a/zlt-commons/zlt-sentinel-spring-boot-starter/src/main/resources/META-INF/spring.factories b/zlt-commons/zlt-sentinel-spring-boot-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 00000000..69f01160
--- /dev/null
+++ b/zlt-commons/zlt-sentinel-spring-boot-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,2 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+com.central.sentinel.config.SentinelAutoConfigure
diff --git a/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerAutoConfiguration.java b/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerAutoConfiguration.java
index 1d30ec72..3eb6a4c8 100644
--- a/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerAutoConfiguration.java
+++ b/zlt-commons/zlt-swagger2-spring-boot-starter/src/main/java/com/central/common/swagger2/SwaggerAutoConfiguration.java
@@ -10,7 +10,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
@@ -38,7 +37,6 @@ import java.util.stream.Collectors;
* @author zlt
* @date 2018/11/18 9:22
*/
-@Configuration
@Import( {
Swagger2Configuration.class
})
diff --git a/zlt-config/src/main/resources/application-dev.properties b/zlt-config/src/main/resources/application-dev.properties
index 775045e2..1a78a814 100644
--- a/zlt-config/src/main/resources/application-dev.properties
+++ b/zlt-config/src/main/resources/application-dev.properties
@@ -17,4 +17,7 @@ zlt.redis.timeout=5000
##### elasticsearch配置
zlt.elasticsearch.cluster-name=docker-cluster
-zlt.elasticsearch.cluster-nodes=120.77.169.48:9300
\ No newline at end of file
+zlt.elasticsearch.cluster-nodes=120.77.169.48:9300
+
+##### sentinel配置
+zlt.sentinel.dashboard=localhost:6999
\ No newline at end of file
diff --git a/zlt-config/src/main/resources/application.properties b/zlt-config/src/main/resources/application.properties
index f8a83309..0a428dc1 100644
--- a/zlt-config/src/main/resources/application.properties
+++ b/zlt-config/src/main/resources/application.properties
@@ -30,7 +30,8 @@ ribbon.ReadTimeout=15000
##### feign配置
-feign.hystrix.enabled=true
+feign.sentinel.enabled=true
+feign.hystrix.enabled=false
feign.okhttp.enabled=true
feign.httpclient.enabled=false
feign.client.config.feignName.connectTimeout=30000
@@ -39,12 +40,27 @@ feign.compression.request.enabled=true
feign.compression.response.enabled=true
-##### hystrix配置
-hystrix.threadpool.default.coreSize=100
-hystrix.threadpool.default.maxQueueSize=1000
-hystrix.threadpool.default.queueSizeRejectionThreshold=800
-# 断路器的超时时间,断路器的超时时间需要大于ribbon的超时时间,不然不会触发重试
-hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=60000
+##### sentinel配置
+spring.cloud.sentinel.transport.dashboard=${zlt.sentinel.dashboard}
+spring.cloud.sentinel.eager=true
+### 动态配置规则
+# 系统负载保护
+spring.cloud.sentinel.datasource.ds1.nacos.server-addr=${zlt.nacos.server-addr}
+spring.cloud.sentinel.datasource.ds1.nacos.dataId=sentinel-system
+spring.cloud.sentinel.datasource.ds1.nacos.groupId=DEFAULT_GROUP
+spring.cloud.sentinel.datasource.ds1.nacos.rule-type=system
+# 限流
+spring.cloud.sentinel.datasource.ds2.nacos.server-addr=${zlt.nacos.server-addr}
+spring.cloud.sentinel.datasource.ds2.nacos.dataId=sentinel-flow
+spring.cloud.sentinel.datasource.ds2.nacos.groupId=DEFAULT_GROUP
+spring.cloud.sentinel.datasource.ds2.nacos.data-type=json
+spring.cloud.sentinel.datasource.ds2.nacos.rule-type=flow
+# 熔断
+spring.cloud.sentinel.datasource.ds3.nacos.server-addr=${zlt.nacos.server-addr}
+spring.cloud.sentinel.datasource.ds3.nacos.dataId=sentinel-degraderule
+spring.cloud.sentinel.datasource.ds3.nacos.groupId=DEFAULT_GROUP
+spring.cloud.sentinel.datasource.ds3.nacos.data-type=json
+spring.cloud.sentinel.datasource.ds3.nacos.rule-type=degrade
##### druid配置
@@ -84,6 +100,7 @@ spring.datasource.druid.stat-view-servlet.reset-enable=true
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.druid.stat-view-servlet.login-password=admin
+
##### redis-jedis连接池配置
#最大等待时间
spring.redis.jedis.pool.max-wait=1000ms
diff --git a/zlt-gateway/zuul-gateway/pom.xml b/zlt-gateway/zuul-gateway/pom.xml
index 69cdd6ea..5ffbd351 100644
--- a/zlt-gateway/zuul-gateway/pom.xml
+++ b/zlt-gateway/zuul-gateway/pom.xml
@@ -11,6 +11,10 @@
+
+ com.zlt
+ zlt-config
+
com.zlt
zlt-auth-client-spring-boot-starter
@@ -21,7 +25,7 @@
com.zlt
- zlt-config
+ zlt-sentinel-spring-boot-starter
diff --git a/zlt-uaa/pom.xml b/zlt-uaa/pom.xml
index aad44cf1..504b5fe1 100644
--- a/zlt-uaa/pom.xml
+++ b/zlt-uaa/pom.xml
@@ -9,6 +9,10 @@
zlt-uaa
认证中心
+
+ com.zlt
+ zlt-config
+
com.zlt
zlt-auth-client-spring-boot-starter
@@ -27,8 +31,9 @@
com.zlt
- zlt-config
+ zlt-sentinel-spring-boot-starter
+
org.springframework.cloud
spring-cloud-starter-alibaba-nacos-discovery
diff --git a/zlt-uaa/src/main/java/com/central/oauth/controller/OAuth2Controller.java b/zlt-uaa/src/main/java/com/central/oauth/controller/OAuth2Controller.java
index 6700664a..b31ec32e 100644
--- a/zlt-uaa/src/main/java/com/central/oauth/controller/OAuth2Controller.java
+++ b/zlt-uaa/src/main/java/com/central/oauth/controller/OAuth2Controller.java
@@ -10,7 +10,6 @@ import com.central.common.utils.SpringUtil;
import com.central.oauth.mobile.MobileAuthenticationToken;
import com.central.oauth.openid.OpenIdAuthenticationToken;
import com.central.oauth.service.impl.RedisClientDetailsService;
-import com.central.oauth2.common.properties.SecurityProperties;
import com.central.oauth2.common.util.AuthUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
@@ -19,8 +18,6 @@ import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.authentication.*;
@@ -71,19 +68,15 @@ public class OAuth2Controller {
@Resource
private UserService userService;
- @Autowired
- private SecurityProperties securityProperties;
-
- @Value("${test2:}")
- private String test2;
-
@GetMapping("/oauth/test")
- public String[] testNacos() {
- return securityProperties.getCode().getIgnoreClientCode();
+ public SysUser testNacos() {
+ return userService.selectByUsername("admin");
}
+
@GetMapping("/oauth/test2")
- public String test2() {
- return test2;
+ public String testNacos2() throws InterruptedException {
+ Thread.sleep(5000);
+ return "success";
}
@ApiOperation(value = "用户名密码获取token")