springCloud之服务降级熔断Hystrix
https://yjtzfywh.blog.csdn.net/article/details/129221212
一、配置监控服务端
1、文件目录
2、依赖
1. <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId> <version>2.2.10.RELEASE</version> </dependency> </dependencies>
3、配置文件
server: port: 8900 hystrix: dashboard: # 将localhost添加到白名单,默认是不允许的 proxy-stream-allow-list: "localhost"
4、启动类
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; @SpringBootApplication @EnableHystrixDashboard public class HystrixDashBoardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashBoardApplication.class,args); } }
5、启动服务打开服务页面
http://localhost:8900/hystrix/
二、配置监控客户端
1、依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> <version>2.2.10.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2、配置
server: port: 8301 # 数据库 spring: application: name: borrowService datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/cloudstudy username: root password: 123456 eureka: client: # 跟上面一样,需要指向Eureka服务端地址,这样才能进行注册 service-url: defaultZone: http://eureka02:8802/eureka,http://eureka02:8801/eureka #Hystrix也可以配合Feign进行降级 feign: circuitbreaker: enabled: true #监控用 management: endpoints: web: exposure: include: '*'
3、启动类
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.hystrix.EnableHystrix; import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication @EnableFeignClients @EnableHystrix public class BorrowApplication { public static void main(String[] args) { SpringApplication.run(BorrowApplication.class,args); } }
启动被监控服务
三、服务端查看监控
http://localhost:8301/actuator/hystrix.stream
调用接口,查看监控变化