🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
<mark>服务降级处理是在客户端实现的,与服务端没有关系</mark>。为了方便演示降级效果,在这里搭建一个客户端模块 cloud-comsumer-feign-hystrix-order80,让它调用服务端模块 cloud-provider-hystrix-payment8001。 <br/> 步骤如下: **1. 构建消费端模块:cloud-comsumer-feign-hystrix-order80** **2. 在当前模块的`pom.xml`中添加 hystrix 依赖** ```xml <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> ... </dependencies> ``` **3. 当前模块的`resources/application.yml`** ```yml server: port: 80 eureka: client: service-url: defaultZone: http://www.eureka7001.com:7001/eureka/,http://www.eureka7002.com:7002/eureka/ spring: application: name: cloud-comsumer-order feign: hystrix: #在feign中开启hystrix支持 enabled: true #要访问的微服务名 provider: payment: name: cloud-payment-service ``` **4. 在当前模块的启动类上标注注解`@EnableHystrix`** ```java @SpringBootApplication @EnableFeignClients @EnableHystrix //该注解已经包含@EnableCircuitBreaker public class OrderHystrixMain80 { public static void main(String[] args) { SpringApplication.run(OrderHystrixMain80.class, args); } } ``` **5. 构建完成!**