2016-09-28 55 views
0

我是Hystrix儀表板的新手。我用Hystrix編寫了示例應用程序。 我想查看Hystrix圖表(命令度量流)。但我得到以下錯誤:Spring Boot中的Hystrix儀表板問題

Circuit: Unable to connect to Command Metric Stream 
Thread Pools: Loading... 

我正在使用STS與Maven。

下面是使用的代碼:

簡單的服務器的microService申請(春季啓動網絡在8085端口上運行)

package hello; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.web.bind.annotation.RestController; 
import org.springframework.web.bind.annotation.RequestMapping; 

@RestController 
@SpringBootApplication 
public class BookstoreApplication { 

    @RequestMapping(value = "/recommended") 
    public String readingList(){ 
    return "Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt)"; 
    } 

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

簡單的客戶端的microService申請(春季啓動網絡端口8095上運行),我已經包括蝟與網絡一起豪豬儀表板的相關性,因此,所有的豪豬依賴是在類路徑

package hello; 

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 
import org.springframework.stereotype.Service; 
import org.springframework.web.client.RestTemplate; 

import java.net.URI; 

@Service 
public class BookService { 

    private final RestTemplate restTemplate; 

    public BookService(RestTemplate rest) { 
    this.restTemplate = rest; 
    } 

    @HystrixCommand(fallbackMethod = "reliable") 
    public String readingList() { 
    URI uri = URI.create("http://localhost:8090/recommended"); 

    return this.restTemplate.getForObject(uri, String.class); 
    } 

    public String reliable() { 
    return "Cloud Native Java (O'Reilly)"; 
    } 

} 


package hello; 

import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; 
import org.springframework.boot.web.client.RestTemplateBuilder; 
import org.springframework.context.annotation.Bean; 
import org.springframework.web.bind.annotation.RestController; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 
import org.springframework.web.client.RestTemplate; 

@EnableHystrixDashboard 
@EnableHystrix 
@EnableCircuitBreaker 
@RestController 
@SpringBootApplication 
public class ReadingApplication { 

    @Autowired 
    private BookService bookService; 

    @Bean 
    public RestTemplate rest(RestTemplateBuilder builder) { 
    return builder.build(); 
    } 

    @RequestMapping("/to-read") 
    public String toRead() { 
    return bookService.readingList(); 
    } 

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

通過運行上面的代碼, hystrix工作正常,當BooKStoreApplication關閉時,它將採用備用方法。

這兩個網址工作正常。 正常情況:

http://localhost:8085/recommended 
Output: Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt) 

http://localhost:8095/to-read 
Output: Spring in Action (Manning), Cloud Native Java (O'Reilly), Learning Spring Boot (Packt) 


When BookStoreApplication is down (http://localhost:8085/recommended) accessing http://localhost:8095/to-read returns "Cloud Native Java (O'Reilly)" as expected. 

但是,當我試圖調用此URL http://localhost:8095/hystrix,我正在豪豬儀表板頁面,索取流值。

我試圖給http://localhost:8095/http://localhost:8095/to-read,並點擊「監控流」,它是要下一個頁面出現錯誤:

Circuit: Unable to connect to Command Metric Stream 
Thread Pools: Loading... 

回答

2

我所經歷的一樣。主要的問題是,我沒有執行器依賴在我的maven pom中。所以我無法得到hystrix流。

  1. 包括彈簧啓動執行器。
  2. 檢查localhost:8085/health是否正在運行。
  3. 嘗試在Hystrix儀表板中輸入localhost:8085/hystrix.stream以流化值。
  4. 執行服務幾次 - >儀表板應顯示受監視的方法/命令。