spring cloud学习——13. Circuit Breaker: Hystrix Clients

13. CircuitBreaker: Hystrix Clients

Hystrix

断路器

13.1 How to Include Hystrix

服务消费者microservice-customer-movie-ribbon-withHistrict2上面写断路器。

如果服务提供者microservice-provider-user异常,就会发生短路,执行写好的程序

1.启动类增加注解@EnableCircuitBreaker

2.controller

@controller
@RestController
public class UseDemoController {

	@Autowired
	private RestTemplate restTemplate;
	
	@RequestMapping("/demo")
	@HystrixCommand(fallbackMethod = "findByIdFallback")//设置断路器,如果连接不上,就执行断路器“findByIdFallback”
	public String useDemo() {
		return restTemplate.getForObject("http://microservice-provider-user/demo/dd", String.class);//参数1使eureka的service-id,是个虚拟主机名,可以用eureka.instance.secure.virtual-host-name定义,如果不是https的,就用eureka.instance.virtual-host-name
	}
	
	//断路器方法
	public String findByIdFallback() {
		return " ----findByIdFallback---";
	}
}

 

13.2Propagating the Security Context orusing Spring Scopes(传播安全上下文,和springscopes)

execution.isolation.strategy  

This property indicates which isolation strategyHystrixCommand.run() executes with,one of the following two choices:隔离策略

THREAD——it executes on a separate thread and concurrent requests are limitedby the number of threads in the thread-pool(它是一个单独的线程上执行,并发请求受线程池中的线程数量的限制,默认策略)

SEMAPHORE——it executes on the calling thread and concurrent requests arelimited by the semaphore count(它在调用线程上执行,并发请求受到信号量计数的限制)

hystrix.shareSecurityContext :spring security上下文

13.3 Health Indicator

/health 暴露了连接的断路器的状态

13.4 Hystrix Metrics Stream

hystrix.stream作为管理端口

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值