## 传播安全上下文或使用Spring Scopes

springcloud原文：

If you want some thread local context to propagate into a @HystrixCommand the default declaration will not work because it executes the command in a thread pool (in case of timeouts). You can switch Hystrix to use the same thread as the caller using some configuration, or directly in the annotation, by asking it to use a different “Isolation Strategy”.

springcloud原文：

The same thing applies if you are using @SessionScope or @RequestScope. You will know when you need to do this because of a runtime exception that says it can’t find the scoped context.

You also have the option to set the hystrix.shareSecurityContext property to true. Doing so will auto configure an Hystrix concurrency strategy plugin hook who will transfer the SecurityContext from your main thread to the one used by the Hystrix command. Hystrix does not allow multiple hystrix concurrency strategy to be registered so an extension mechanism is available by declaring your own HystrixConcurrencyStrategy as a Spring bean. Spring Cloud will lookup for your implementation within the Spring context and wrap it inside its own plugin.

## 健康指标

spring-boot的actuator提供了/health端点来查看Hystrix状态。使用也很简单，在pom.xml增加依赖即可：

springboot-acturator的相关内容参考：http://www.cnblogs.com/yjmyzz/p/spring-boot-actuator-tutorial.html

## Hystrix监控

/health端点只能看到断路器的整体状态，但对细节展示不详细。从上面我们会看到一个/hystrix.stream的端点，访问该端点可以看到详细的数据。页面会一直持续刷新，可以看到最新数据。

## Hystrix Dashboard

a.添加spring-cloud-starter-hystrix-dashboard的依赖

b.在启动类上增加@EnableHystrixDashboard注解

c.重新启动movie-hystrix模块
d.浏览器输入movie-hystrix应用端口/hystrix，可以看到下面的页面