2016-09-28 10 views
0

Hystrix 대시 보드를 처음 사용했습니다. Hystrix로 샘플 애플리케이션을 작성했습니다. Hystrix 차트 (명령 메트릭 스트림)를보고 싶습니다. 그러나 아래 오류가 나타납니다 :스프링 부트의 Hystrix 대시 보드 문제

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

Maven과 함께 STS를 사용하고 있습니다.

간단한 서버 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에서 실행이) 내가 포함했다 : 아래

사용되는 코드입니다 Hystrix 및 웹과 함께 Hystrix 대시 보드의 의존성 때문에 모든 Hystrix 종속성, 위의 코드를 실행하여 클래스 경로

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이 다운되었을 때 fallback 메소드로 넘어갑니다.

두 URL 모두 정상적으로 작동합니다. 일반 케이스 :이 URL http://localhost:8095/hystrix를 호출하려고 할 때

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. 

을하지만, 나는 Hystrix DashBoard를 페이지를 받고 스트림 값을 요청하고있다.

가 나는 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. 로컬 호스트 : 8085/hystrix.stream을 입력하여 Hystrix 대시 보드의 값을 스트리밍하십시오.
  4. 서비스를 몇 번 실행하십시오. -> 대시 보드에 모니터링 된 메소드/명령이 나타나야합니다.
관련 문제