1 Star 0 Fork 61

Robert_Q_Chen / Spring Cloud Alibaba

forked from huan1993 / Spring Cloud Alibaba 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Spring Cloud Alibaba

介绍

Spring Cloud Alibaba 学习,学习各个组件的使用
版本选择说明

项目介绍

spring-cloud-alibaba-parent
│ |- 父项目
├─nacos-discovery [博客](https://blog.csdn.net/fu_huo_1993/article/details/109257707)
│ |- 注册中心
│ │- user-consumer-9091
| |		 >> 1、只作为服务消费者,不注册 nacos 上
│ │					** spring.cloud.nacos.discovery.register-enabled = false
│ │    >> 2、配置 nacos 服务地址
│ │         ** spring.cloud.nacos.discovery.server-addr=地址,不需要[http|https]
│ │    >> 3、自定义注册到 nacos 上的服务名,默认是获取的spring.application.name的值
│ │         ** spring.cloud.nacos.discovery.service=服务名
│ │    >> 4、集成ribbon
│ │    			** ribbon.nacos.enabled=true  true=集成,false=不集成
│ │    >> 5、从nacos上移除改服务
│ │    			@Autowired
│ │             private NacosServiceManager nacosServiceManager;
│ │             @Autowired
│ │             private NacosDiscoveryProperties nacosDiscoveryProperties;
│ │
│ │             # 修改nacos上这个服务的健康状态为不健康,此时该服务还是可以对外提供服务的。
│ │             nacosServiceManager.nacosServiceShutDown()
│ │
│ │- user-provider-9092
│ │- user-provider-9093
│ │    >> 1、服务提供者,注册到 nacos 上。
│ │					** spring.cloud.nacos.discovery.register-enabled = true
│ │    >> 2、设置元数据。
│ │					** spring.cloud.nacos.discovery.metadata  (key value) 格式
│ │    >> 3、命名空间的配置。
│ │					** spring.cloud.nacos.discovery.namespace 用于区分不同的环境,比如 dev、local等,需要写 命名空间ID 的值
│ │    >> 4、配置组,不同的服务可以划分到一个组,默认是 DEFAULT_GROUP。
│ │					** spring.cloud.nacos.discovery.group
│ │    >> 5、配置集群,默认值是 DEFAULT
│ │					** spring.cloud.nacos.discovery.cluster-name
├─nacos-ribbon
│ |- nacos 整合ribbon,默认就整合了ribbon
│ │- user-consumer-9091
| |		 >> 1、自定义负载均衡策略,使之整合nacos的权重 
│ │					** NacosWeightRule
│ │    >> 2、需要注意 Spring 的父子上下文,否则很容易导致为某个服务配置的规则导致应用到全部的微服务上。
│ │- user-provider-9092
│ │- user-provider-9093
│ │    >> 1、配置微服务权重
│ │         ** spring.cloud.nacos.discovery.weight 1-100,值越大,权重越大
├─sentinel [博客](https://blog.csdn.net/fu_huo_1993/article/details/109271114)
│ |- nacos 整合 sentinel
│ │- user-consumer-9099
| |		 >> 1、整合 sentinel 配置 sentinel dashboard 的 url 和 通讯端口 
| |		 >> 2、整合 Feign
| |		 >> 3、整合 RestTemplate
| |		 >> 4、生产环境使用 sentinel https://github.com/alibaba/Sentinel/wiki/%E5%9C%A8%E7%94%9F%E4%BA%A7%E7%8E%AF%E5%A2%83%E4%B8%AD%E4%BD%BF%E7%94%A8-Sentinel
│ │- product-provider-9098
| |		 >> 1、自定义 BlockExceptionHandler ,实现降级或限流时返回一个默认值
│ │- user-provider-9097
│ │- user-provider-9098
├─gateway [博客](https://blog.csdn.net/fu_huo_1993/article/details/109405439)
│ |- Spring Cloud Gateway route predicate factory的一些用法
│ │- gateway-9102
│ │    1、gateway 的一些基本用法│
│ │    2、spring.cloud.gateway.enabled 用来配置是否启动网关
│ │    3、spring.cloud.gateway.routes[index].uri=[http|lb] lb表示负载均衡的地址 eg: lb:service-name
│ │    4、route predicate factory 的使用
│ │    5、自己编写一个 Route Predicate Factory(git commitid b70f2598)
│ │- gateway-error-9103
│ │    1、网关层面的异常处理
│ │- product-provider-9101
│ │- user-consumer-9100
├─gateway-filter [博客](https://blog.csdn.net/fu_huo_1993/article/details/109427564)
│ |- Spring Cloud Gateway filter 的一些用法
│ │- gateway-9103
│ │    1、gateway filter 的一些基本用法
│ │    2、实现修改 RequestBody 
│ │    3、StripPrefix 可以去掉路由匹配的前缀
│ │    4、PrefixPath 可以为下游服务增加一个前缀
│ │    5、uri 使用 lb://xxx 时,默认使用的阻塞的 ribbon LoadBalancerClient,推荐使用 ReactiveLoadBalancerClientFilter,开启方法设置 spring.cloud.loadbalancer.ribbon.enabled = false
│ │    6、配置 默认拦截器,对所有的路由都会生效,spring.cloud.gateway.default-filters:......
│ │    7、配置 全局过滤器,所有的路由都生效,全局过滤器有顺序,需要实现 GlobalFilter 和 Ordered 接口
│ │    8、实现一个 全局过滤器 CustomGlobalFilter
│ │    9、实现一个 GatewayFilter TokenGatewayFilterFactory
│ │    10、获取当前路由,获取过滤器执行顺序 参考 GetCurrentRouteAndSortGatewayFilterFactory
│ │    11、指定网关全局和局部的超时时间
│ │    12、处理网关异常。GatewayExceptionHandler
│ │    13、输出调试日志。
│ │- product-provider-9104
│ │- user-consumer-9105
├─gateway-oauth2 [博客](https://blog.csdn.net/fu_huo_1993/article/details/119914696?spm=1001.2014.3001.5501)
│ |- Spring Cloud Gateway 整合 Oauth2 实现认证操作
│ │- authorization-server-prod
│ │    1、认证服务器,具体搭建参考 https://blog.csdn.net/fu_huo_1993/article/details/118798160?spm=1001.2014.3001.5501
│ │- user-provider
│ │    1、用户服务,对外提供一个 获取所有用户的接口
│ │    1、获取网关服务传递下来的token信息,也可以传递具体的认证数据
│ │- gateway
│ │    1、实现网关的认证
│ │    2、向下游服务的请求头中传递解码后的token数据
│ │    3、整合 oauth2 资源服务器,实现验证权限操作
├─gateway-redis-limiter [博客](https://blog.csdn.net/fu_huo_1993/article/details/120155756?spm=1001.2014.3001.5501)
│ │- gateway
│ │    1、实现网关限流
│ │    2、实现限流后,返回自定义的响应码给客户端
│ │    3、实现自定义的限流key
│ │    4、实现自定义的限流算法
│ │    5、RequestRateLimiter 过滤器只能使用 name,args的方式来配置
├─nacos-config [博客](https://blog.csdn.net/fu_huo_1993/article/details/109923909)
│ |- Spring Cloud Alibaba Nacos Config 的一些用法
│ │- product-provider-9200
│ │    1、如何确定加载一个配置文件
│ │    2、配置的刷新
│ │    3、实现加载多个配置文件
│ │    4、加载的顺序
│ │    5、nacos config 配置相关的内容需要放置在 bootstrap.yml 配置文件中
│ │    6、@RefreshScope在定时任务中的坑
│ │    7、@Value配置的值在线程中的坑
│ │    8、最好不要出现优先级上的配置
├─gateway-dynamic-refresh-route [博客](https://blog.csdn.net/fu_huo_1993/article/details/117997210)
│ │- gateway-9201
│ │    1、完成网关配置的自动刷新,不需要额外的配置,只需要 Spring Cloud Alibaba Nacos Config 和 Spring Cloud Gateway 整合,网关配置放到 nacos 上即可实现。

微信公众号

更多内容请关注微信公众号

更多内容请关注微信公众号

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

1、Spring Cloud、Spring Cloud Alibaba、Spring Boot 版本说明

MIT License Copyright (c) 2020 huan1993 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Spring Cloud Alibaba 学习 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/robert_may/spring-cloud-alibaba-parent.git
git@gitee.com:robert_may/spring-cloud-alibaba-parent.git
robert_may
spring-cloud-alibaba-parent
Spring Cloud Alibaba
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891