您现在的位置是:主页 > news > 页面菜单 wordpress/西安关键词排名优化
页面菜单 wordpress/西安关键词排名优化
admin2025/6/6 21:16:51【news】
简介页面菜单 wordpress,西安关键词排名优化,wordpress的页面的,看网站是不是WP做的SpringCloud Fegin默认已为Feign整合了hystrix,所以添加Feign依赖后就不用在添加hystrix,那么怎么才能让Feign的熔断机制生效呢,只要按以下步骤开发:一,添加feign依赖 <!--springCloud整合feign--><dependenc…
页面菜单 wordpress,西安关键词排名优化,wordpress的页面的,看网站是不是WP做的SpringCloud Fegin默认已为Feign整合了hystrix,所以添加Feign依赖后就不用在添加hystrix,那么怎么才能让Feign的熔断机制生效呢,只要按以下步骤开发:一,添加feign依赖 <!--springCloud整合feign--><dependenc…
SpringCloud Fegin默认已为Feign整合了hystrix,所以添加Feign依赖后就不用在添加hystrix,那么怎么才能让Feign的熔断机制生效呢,只要按以下步骤开发:
一,添加feign依赖
<!--springCloud整合feign--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency>
二,配置application.yml 在Feign中开启hystrix
在Feign中已经内置了hystrix,但是默认是关闭的需要在工程的 application.yml 中开启对hystrix的支持
server:port: 9013tomcat:max-threads: 10 # 设置线程数为最大10个
spring:application:name: service-order-hystrixdatasource:driver-class-name: com.mysql.jdbc.Driverurl: jdbc:mysql://localhost:3306/springclouddemo?useUnicode=true&characterEncoding=utf8&serverTimezone=UTCusername: rootpassword: rootjpa:database: MySQLshow-sql: trueopen-in-view: true
eureka:client:service-url:defaultZone: http://localhost:9003/eureka/,http://localhost:9004/eureka/instance:prefer-ip-address: trueinstance-id: ${spring.cloud.client.ip-address}:${server.port} #向注册中心中展示注册服务idlease-expiration-duration-in-seconds: 10 #eureka client 发送心跳给server端后,续约到期时间(默认为90秒)。lease-renewal-interval-in-seconds: 5 # 发送心跳续约间隔(每一个心跳的间隔)
#修改ribbon的负载均衡策略 服务名-ribbon-NFLoadBalancer
service-product:ribbon:NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRuleConnectTimeout: 250 # Ribbon的连接超时时间ReadTimeout: 3000 # Ribbon的数据读取超时时间OkToRetryOnAllOperations: true # 是否对所有操作都进行重试MaxAutoRetriesNextServer: 1 # 切换实例的重试次数MaxAutoRetries: 1 # 对当前实例的重试次数feign:client:config:service-product: # 服务提供者的服务名称loggerLevel: FULLhystrix:enabled: true
logging:level:com.zjk.order.feign.productFeignHttpClient: debug #feign的自定义接口
三,修改productFeignClient添加hystrix熔断
//指定需要调用的服务名称
@FeignClient(name = "service-product",fallback = ProductFeignClientCallBack.class)
public interface productFeignHttpClient {//调用的请求路径@RequestMapping(value = "/product/{Id}",method = RequestMethod.GET)public TbProduct findById(@PathVariable("Id") Long Id);
}
四,配置FeignClient接口的实现类
@Component
public class ProductFeignClientCallBack implements productFeignHttpClient {@Overridepublic TbProduct findById(Long Id) {TbProduct tbProduct = new TbProduct();tbProduct.setProductName("服务降级");return tbProduct;}
}
@FeignClient注解中以fallback声明降级方法