根据doc,我的应用程序应在/ health下提供hystrix数据。尽管打开了断路器,但我在该URL下看到的唯一一件事是
{"status":"UP"}
我希望看到这样的东西
{
"hystrix": {
"openCircuitBreakers": [
"somedata::somedata"
],
"status": "CIRCUIT_OPEN"
},
"status": "UP"
}
我错过了什么?
我的build.gradle
buildscript {
ext {
springBootVersion = '1.5.10.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
group = 'com.somecompany'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
ext {
springCloudVersion = 'Edgware.SR1'
}
dependencies {
compile('org.springframework.cloud:spring-cloud-starter-hystrix')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-actuator')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
应用类别
@EnableCircuitBreaker
@SpringBootApplication
public class HystrixDemoApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDemoApplication.class, args);
}
}
Hystrix控制下的资源
@RestController
public class SomeResourceController {
@HystrixCommand(fallbackMethod = "defaultValue", commandProperties = {@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value="1500")})
@RequestMapping(path = "/resource-with-hystrix", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public String someResource(){
URI uri = URI.create("http://localhost:8080/some-resource");
RestOperations restTemplate = new RestTemplate();
return restTemplate.getForObject(uri, String.class);
}
private String defaultValue(){
return "local value in case of something goes wrong";
}
}
最佳答案
将运行状况端点设置为不敏感(默认):
endpoints.health.sensitive=false
根据暴露端点的方式,敏感属性可以用作安全提示。例如,通过HTTP访问敏感端点时,它们将需要用户名/密码(如果未启用Web安全,则将其禁用)。
从运行状况端点的文档中:
显示应用程序的运行状况信息(当应用程序是安全的时,通过未经身份验证的连接访问时为简单的“状态”,而在经过身份验证时则为完整的消息详细信息)。
关于java - Hystrix的状态未在/health下公开,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48704018/