gpt4 book ai didi

java - Hystrix状态未暴露在/health下

转载 作者:行者123 更新时间:2023-12-01 19:58:22 24 4
gpt4 key购买 nike

根据doc我的应用程序应该在/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";
}
}

最佳答案

根据documentation :

The information exposed by the health endpoint depends on the management.endpoint.health.show-details property <...> The default value is never.

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

  • when_authorized
  • 永远

像这样:

management.endpoint.health.show-details = always

msfoster 提供的答案不再有效(从 Spring Boot 2.1.x 和云发布列车 Greenwich.RELEASE 开始):

Endpoint sensitive flag is no longer customizable as Spring Boot no longer provides a customizable security auto-configuration . Create or adapt your security configuration accordingly

关于java - Hystrix状态未暴露在/health下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48704018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com