无法在春季启动应用程序中设置Hystrix仪表板

时间:2018-07-04 09:28:55

标签: java spring spring-boot hystrix

我正在尝试为我的Java Spring Boot应用程序设置一个hystrix仪表板。启动应用程序后,我在控制台中收到代理打开消息,但是什么也没有发生。

Proxy opening connection to: http://localhost:9083/actuator/hystrix.stream

在信息中心中,它显示正在加载...,什么也没有显示...请参阅底部的图片。

此外,当我在浏览器中点击此网址http://localhost:9083/actuator/hystrix.stream时,没有数据显示,只是持续的空ping。喜欢
ping:
ping:
ping:
...

我所做的代码更改是

@RequestMapping(value = "/elasticsearch/{numberOfInstances}/{name}", method = RequestMethod.GET)
    public void ingestMip4DataToES(@PathVariable("numberOfInstances") int numberOfInstances,
            @PathVariable("name") String name) {

        if(numberOfInstances > 1) {
            List<IdentifiableType> identifiableTypes = generateMultipleInstancesOfMip4Data(numberOfInstances, name);
            if(!identifiableTypes.isEmpty()) {
                dumpBulkMip4DataToES(identifiableTypes);                
            }
        } else {
            IdentifiableType identifiableType = generateSingleInstanceOfMip4Data(name);
            if(identifiableType != null) {
                dumpMip4DataToES(identifiableType);             
            }
        }
    }
@HystrixCommand(fallbackMethod = "fallbackForMip4SingleDataGeneration")
    private IdentifiableType generateSingleInstanceOfMip4Data(String name) {
        String url = GENERATOR_URL + name;

        ResponseEntity<IdentifiableType> response = restTemplate.getForEntity(url, IdentifiableType.class);
        return response.getBody();
    }

private IdentifiableType fallbackForMip4SingleDataGeneration() {
        logger.info("Calling fallback method for mip4 data generation as request to service failed.");
        return null;
    }

在主类上包含必需的注释。

@SpringBootApplication
//@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableHystrixDashboard
public class InsaneMip4ElasticSearchApplication {

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

资源文件包含以下条目

management.endpoints.web.exposure.include=*
management.endpoints.web.exposure.include=hystrix.stream
management.endpoints.jmx.exposure.include=*
management.endpoint.health.show-details=ALWAYS
management.endpoint.shutdown.enabled=true

并为以下pom文件创建了条目

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

Hystrix仪表盘如下所示 enter image description here

2 个答案:

答案 0 :(得分:0)

由于我进行了错误的配置,因此仪表板为空。 HystrixCommand应该附加到用RequestMapping注释的方法上。这是因为Hystrix监视api端点。

因此,进行以下更改会使事情对我有用。

@HystrixCommand(fallbackMethod = "fallbackForMip4DataGeneration")
    @RequestMapping(value = "/elasticsearch/{numberOfInstances}/{name}", method = RequestMethod.GET)
    public void ingestMip4DataToES(@PathVariable("numberOfInstances") int numberOfInstances,
            @PathVariable("name") String name) {

        if(numberOfInstances > 1) {
            List<IdentifiableType> identifiableTypes = generateMultipleInstancesOfMip4Data(numberOfInstances, name);
            if(!identifiableTypes.isEmpty()) {
                dumpBulkMip4DataToES(identifiableTypes);                
            }
        } else {
            IdentifiableType identifiableType = generateSingleInstanceOfMip4Data(name);
            if(identifiableType != null) {
                dumpMip4DataToES(identifiableType);             
            }
        }
    }

    private void fallbackForMip4DataGeneration(int numberOfInstances, String name) {
        logger.info("Calling fallback method for mip4 data generation as request to service failed.");
    }

如您所见,现在@HystrixCommand批注已应用于ingestMip4DataToES()方法,因为该方法具有@RequestMapping批注。先前将@HystrixCommand应用于generateSingleInstanceOfMip4Data()方法不正确。

现在,当我致电http://localhost:9083/mip4/elasticsearch/1/CUnitType时,我可以在hystrix仪表板上看到对该呼叫的实时监视。

如果使用Springboot 2(2.0.2.RELEASE)进行监视,请记住通过http://host:port/hystrix访问仪表板并在URL中应用http://host:port/actuator/hystrix.stream

答案 1 :(得分:0)

请在您的@RequestMapping中添加@HystrixCommand(fallbackMethod =“ fallbackForMip4SingleDataGeneration”),然后尝试多次访问@RequestMapping网址。访问完所需的@RequestMapping网址后,请转到hystrix.stream,您将找到必要的信息。