标签:假设 and pid col 条件 就是 names star pos
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
eureka:
client:
service-url:
defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka,http://eureka7003.com:7003/eureka
instance:
instance-id: microservice-dept-provider-hystrix
prefer-ip-address: true
@RestController
@RequestMapping("/dept")
public class DeptController {
@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
@HystrixCommand(fallbackMethod = "processHystrix_Get")
public Dept get(@PathVariable("id") Long id){
Dept dept = deptService.get(id);
if(null == dept){
throw new RuntimeException("该ID:"+ id +"没有对应的信息");
}
return dept;
}
// 一旦调用服务方法失败并抛出了错误消息后,会自动调用@HystrixCommand标注好的fallbackMethod调用类中的指定方法
public Dept processHystrix_Get(@PathVariable("id") Long id){
Dept dept = new Dept();
dept.setDeptno(id);
dept.setDname("该ID: "+ id +"没有对应的信息,null-HystrixCommand");
dept.setDb_source("no this database in MySQL");
return dept;
}
}
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableCircuitBreaker
public class DeptProviderHystrixApplication {}
@Component
public class DeptClientServiceFallbackFactory implements FallbackFactory<DeptClientService> {
@Override
public DeptClientService create(Throwable throwable) {return new DeptClientService() {
@Override
public Dept get(Long id) {
Dept dept = new Dept();
dept.setDeptno(id);
dept.setDname("该ID: "+ id +"没有对应的信息,Consumer 客户端提供的降级服务,此刻服务Provider已经关闭");
dept.setDb_source("no this database in MySQL");
return dept;
}
@Override
public List<Dept> list() {
return null;
}
@Override
public boolean add(Dept dept) {
return false;
}
};
}
}
//@FeignClient(value = "MICROSERVICECLOUD-DEPT-PROVIDER")
@FeignClient(value = "MICROSERVICECLOUD-DEPT-PROVIDER",fallbackFactory = DeptClientServiceFallbackFactory.class)
public interface DeptClientService { }
feign: // 新增配置
hystrix:
enabled: true
当服务端Provider已经down后, 由于做了服务降级处理,让客户端在服务端不可用时也会获取提示信息而不会挂起耗死服务器。
服务熔断: 当某个异常条件被触发,直接熔断整个服务,而不是一直等到此服务超时。
服务降级: 从整体负荷考虑,当某个服务熔断之后,服务端不能再被调用。此时客户端自己准备一个本地的fallback回调,返回一个缺省值。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
server:
port: 9003
hystrix:
dashboard:
proxy-stream-allow-list: localhost
@SpringBootApplication
@EnableHystrixDashboard
@EnableCircuitBreaker
public class DeptConsumerDashboardApplication { }
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
management:
endpoints:
web:
exposure:
include: ‘*‘
2021-01-08 13:40:20.941 WARN 8136 --- [nio-9003-exec-3] ashboardConfiguration$ProxyStreamServlet : Origin parameter: http://localhost:8004/actuator/hystrix.stream is not in the allowed list of proxy host names. If it should be allowed add it to hystrix.dashboard.proxyStreamAllowList.
Delay: 用来控制服务器上轮询监控信息的延迟时间,默认为2000毫秒,通过配置该属性来降低客户端的网络和CPU消耗。
Title: 对应头部标题Hystrix Stream之后的内容,默认会使用具体监控实例的URL,通过配置该属性来展示更合适的标题。
实心圆: 有两种含义。 通过颜色的变化代表了实例的健康程度,健康度从绿色 < 黄色 < 橙色 < 红色 递减。
实心圆大小也会根据实例的请求流量发生变化, 流量越大该实心圆就越大。通过实心圆可以在大量实例中快速发现故障实例和高压力实例。
标签:假设 and pid col 条件 就是 names star pos
原文地址:https://www.cnblogs.com/kingdomer/p/14250772.html