【问题标题】:Spring Cloud: Hystrix shows no data on pingSpring Cloud:Hystrix 在 ping 上显示没有数据
【发布时间】:2017-01-01 11:11:20
【问题描述】:

我在我的 Spring Boot 应用程序中使用 hystrix,但是当我访问 /hystrix-stream 页面时没有数据。它只显示“ping:”。 在我的 pom.xml 我有以下内容:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-ribbon</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

我已启用 Hystrix 和 HystrixDashboard。此外,我在我的应用程序中使用功能区。 HystrixCommand 如下所示:

@HystrixCommand(fallbackMethod = "defaultFallback")
public byte[] doGet() {
    return this.restTemplate.getForObject("http://myInstance/api/v3/ressource",byte[].class);
}

public byte[] defaultFallback() {
    System.out.println("Now doing fallback!");
    return null;
}

当我关闭 myInstance 时,没有调用回退,功能区只显示此失败:

There was an unexpected error (type=Internal Server Error, status=500).
I/O error on POST request for "http:/myInstance/api/v3/ressource": Connection
refused; nested exception is java.net.ConnectException: Connection refused

【问题讨论】:

  • 你从哪里调用 doGet 方法?来自同一个班级还是来自某个外部班级?
  • 你有完整的堆栈跟踪吗?

标签: java spring spring-cloud hystrix spring-cloud-netflix


【解决方案1】:

您的 Spring Boot 应用程序必须启用断路器。

像下一个例子:

@EnableCircuitBreaker
@SpringBootApplication
@EnableDiscoveryClient
@EnableWebMvc
public class ClientManagerApp {

    public static void main(String[] args) {
        SpringApplication.run(ClientManagerApp.class, args);
    }
}

【讨论】:

    猜你喜欢
    • 2016-06-17
    • 2021-10-24
    • 1970-01-01
    • 2021-07-09
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多