Hystrix状态未在/ health下公开

时间:2018-02-09 10:41:22

标签: java spring-boot hystrix spring-boot-actuator

根据https://cloud.spring.io/spring-cloud-netflix/multi/multi__circuit_breaker_hystrix_clients.html,我的应用程序应该在/ health下提供hystrix数据。尽管开放式断路器,我在该网址下看到的唯一内容是

{"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";
    }
}

2 个答案:

答案 0 :(得分:2)

根据documentation

  

运行状况端点公开的信息取决于management.endpoint.health.show-details属性<...>默认值为never

因此,为了显示hystrix信息,您需要将management.endpoint.health.show-details设置为以下任意一项:

  • 何时授权
  • 总是

像这样:

management.endpoint.health.show-details = always

msfoster提供的答案不再起作用(自Spring Boot 2.1.x和云发布列车Greenwich.RELEASE起):

  

端点敏感标记不再可自定义,因为Spring Boot不再提供可自定义的安全性自动配置。相应地创建或调整您的安全配置

答案 1 :(得分:1)

将Health端点设置为不敏感(默认):

endpoints.health.sensitive=false
  

根据端点的暴露方式,敏感属性可用作安全提示。例如,敏感端点在通过HTTP访问时需要用户名/密码(如果未启用Web安全性,则只需禁用)。

来自健康终端的文档:

  

显示应用程序运行状况信息(当应用程序是安全的时,通过未经身份验证的连接访问时的简单'状态'或经过身份验证时的完整消息详细信息)。

相关问题