
SpringCloud 2.x学习笔记
程裕强
开源是人类最大的公益事业!--程裕强
展开
-
Spring Cloud 2.x完整入门Demo样例(Greenwich版本)
1、新建Maven项目<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocatio...原创 2019-05-28 19:21:28 · 14932 阅读 · 4 评论 -
SpringCloud 2.x学习笔记:15、Spring Cloud Gateway之Filter过滤器(Greenwich版本)
1、AddRequestHeader过滤器server: port: 7013---spring: cloud: gateway: routes: - id: add_request_header_route uri: http://httpbin.org filters: - AddRequestHea...原创 2019-06-21 17:36:08 · 1894 阅读 · 2 评论 -
SpringCloud 2.x学习笔记:16、Spring Cloud Gateway之限流(Greenwich版本)
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apach...原创 2019-06-27 10:53:29 · 874 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:10、断路器监控(Hystrix Dashboard)(Greenwich版本)
Hystrix 已经停止开发了,Hystrix 官方推荐替代的开源组件:Resilience4j(感觉学不动啦)除了 Resilience4j,还有Spring Cloud Alibaba作为替代组件,首个版本Spring Cloud for Alibaba 0.2.0现在 Spring Boot 有两条线,即 Spring Boot 1.x 和 Spring Boot 2.x,所以 0.2...原创 2019-06-18 19:16:19 · 818 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:22、使用Sentinel实现接口限流
部署Sentinel Dashboardhttps://github.com/alibaba/Sentinel/releases下载jar包,并上传至服务器[root@elastic1 app]# lltotal 20548drwxr-xr-x 9 root root 4096 Jun 28 16:34 nacos-rw-rw-r-- 1 elastic elast...原创 2019-07-08 13:40:41 · 1568 阅读 · 0 评论 -
Sentinel使用Nacos存储规则
参考:http://blog.didispace.com/spring-cloud-alibaba-sentinel-2-1/准备服务启动Nacos:http://10.17.12.160:8848Sentinel Dashboard:http://10.17.12.158:8084新建测试模块sentinel-nacospom.xml<?xml version="1.0" en...原创 2019-07-08 15:00:55 · 6244 阅读 · 1 评论 -
SpringCloud 2.x学习笔记:17、Spring Cloud Gateway之服务注册与发现(Greenwich版本)完整代码
一共三个模块,服务注册模块eureka-server、服务提供模块service-hello和网关模块service-gateway。1、eureka-server模块1.1 pom<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x...原创 2019-06-27 09:52:26 · 871 阅读 · 0 评论 -
限流与熔断降级
通过@SentinelResource来指定出现限流和降级时候的异常处理策略。pom.xml<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"...原创 2019-07-08 16:13:45 · 705 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:18、使用Nacos作为服务注册发现组件(Greenwich版本)
1、Nacoshttps://github.com/alibaba/nacos/releaseshttp://10.17.36.27:8848/nacos2、简单例子演示2.1 父级Maven项目<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4...原创 2019-06-28 09:55:54 · 2071 阅读 · 1 评论 -
SpringCloud 2.x学习笔记:19、使用Nacos作为配置中心
改造nacos-provider如下1、pom.xml<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schem...原创 2019-06-28 14:03:17 · 1735 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:20、Nacos的数据持久化(MySQL)
1、Nacos集群的基础需求参考:http://blog.didispace.com/spring-cloud-alibaba-4/在搭建Nacos高可用集群之前,我们需要先修改Nacos的数据持久化配置为MySQL存储。如果启动多个默认配置下的Nacos节点,数据存储是存在一致性问题的。为了解决这个问题,Nacos采用了集中式存储的方式来支持集群化部署(目前只要支持MySQL的存储)。与...原创 2019-06-28 16:12:57 · 1689 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:9、Spring Cloud Eureka Server HA高可用 (3个节点) (Greenwich版本)
项目信息<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http...原创 2019-06-17 13:52:38 · 525 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:8、Spring Cloud Sleuth(Greenwich版本)
1、服务追踪组件zipkinSpring Cloud Sleuth集成了zipkin组件2、构建server-zipkin从spring Cloud为F版本开始,已经不需要自己构建Zipkin Server了,只需要下载jar运行即可。命令:java -jar zipkin-server-2.12.9-exec.jarD:\Users\chengyq>c:C:\>java...原创 2019-06-17 09:50:54 · 949 阅读 · 0 评论 -
Spring Cloud 2.x学习笔记:2、feign改进(Greenwich版本)
1、Feign简介Feign 整合了ribbon,具有负载均衡的能力;Feign 采用的是基于接口的注解2、新建模块新建一个服务消费者模块consumer-feign,代码结构如下图所示。2.1 pom文件<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM...原创 2019-05-31 10:40:21 · 1743 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:3、Hystrix(Greenwich版本)
1、Hystrix基本思想在分布式系统当中,服务之间调用关系会随着业务的发展而变的复杂,一个服务可能依赖多个服务,服务之间层层依赖;一个服务的瘫痪可能导致整个系统的崩溃。与电闸思想类似:每栋房子,每户都安装了电闸,电闸的作用是保证有一家电路出现短路时,电闸进行断电跳闸的操作,这样不至于导致整栋楼用电瘫痪。2、新建hystrix模块2.1 pom文件<?xml version="1....原创 2019-05-31 14:06:52 · 757 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:4、Zuul(Greenwich版本)
1、Zuul简介zuul 是netflix开源的一个API Gateway 服务器, 本质上是一个web servlet应用。请参考官方文档:https://springcloud.cc/spring-cloud-dalston.html#_router_and_filter_zuulZuul的主要功能是路由转发和过滤器。路由功能是微服务的一部分,比如/api/user转发到到user服务...原创 2019-05-31 15:25:05 · 2274 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:5、Config(Greenwich版本)
说明:参考 https://www.fangzhipeng.com/springcloud/2019/02/21/config-jdbc.html1、Config介绍在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在spring cloud config 组件中,分两个角色,一是config server,二是config client。...原创 2019-06-12 17:01:45 · 688 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:6、高可用的分布式配置中心(Greenwich版本)
1、复用服务注册中心参考https://blog.youkuaiyun.com/chengyuqiang/article/details/90645498spring.application.name=register-serverserver.port=8800eureka.client.register-with-eureka=falseeureka.client.fetch-registry=...原创 2019-06-13 15:26:33 · 600 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:7、Spring Cloud Bus(Greenwich版本)
2019-06-13 15:40:22.332 WARN 11000 --- [nio-8083-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not...原创 2019-06-13 16:32:05 · 1234 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:11、断路器聚合监控(Hystrix Turbine)(Greenwich版本)
http://localhost:7060/personalized/1http://localhost:7090/turbine.stream?cluster=USER-SERVICEhttp://localhost:7090/turbine.stream?cluster=RECOMMEND-SERVICEhttp://localhost:7090/hystrixhttp://...原创 2019-06-19 16:29:26 · 1155 阅读 · 1 评论 -
SpringCloud 2.x学习笔记:12、Spring Cloud Gateway简单例子(Greenwich版本)
1、Spring Cloud Gateway介绍Spring Cloud Gateway是Spring Cloud官方推出的第二代网关框架,取代Zuul网关。2、简单例子演示(1)父级pom<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" ...原创 2019-06-20 10:30:56 · 2202 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:14、Spring Cloud Gateway路由断言工厂(Greenwich版本)
After路由断言After Route Predicate Factory,可配置一个UTC时间格式的时间参数,当请求进来的当前时间在路由断言工厂之后会成功匹配,才交给 router去处理。否则则报错,不通过路由。<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/PO...原创 2019-06-21 09:41:50 · 2065 阅读 · 0 评论 -
SpringCloud 2.x学习笔记:21、Nacos集群模式部署
官方参考文档https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html编辑集群配置文件分别在三个节点上编辑集群配置文件[root@elastic3 conf]# vi cluster.conf[root@elastic3 conf]# cat cluster.conf# ip:port10.xx.xx.xx1:884810.x...原创 2019-06-28 16:45:58 · 6096 阅读 · 0 评论