一 、 Hystrix 대시 보드
효과:
- 각 Hystrix commandKey의 다양한 표시기 값을 실시간으로 모니터링
- 대시 보드의 실시간 모니터링을 통해 다양한 구성을 동적으로 수정
대시 보드 :
2. Hystrix 대시 보드 시작
1 、 下载 standalone-hystrix-dashboard-1.5.3-all.jar
- 다운로드 주소 : https://search.maven.org/search , 상자에 standalone-hystrix-dashboard 쿼리를 입력 한 다음 다운로드합니다.
2. Hystrix 대시 보드 시작
java -jar -DserverPort = 7979 -DbindAddress = localhost standalone-hystrix-dashboard-1.5.3-all.jar
참고 : serverPort 및 bindAddress는 선택적 매개 변수이며 추가되지 않은 경우 기본값은 7979 및 localhost입니다.
3. 시작 성공 여부 확인
- 브라우저에 http : // localhost : 7979 / hystrix-dashboard /를 입력하면 곰 페이지가 정확합니다.
셋, 코드
1, pom.xml
<!-- https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-core -->
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-core</artifactId>
<version>${
hystrix-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-javanica -->
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-javanica</artifactId>
<version>${
hystrix-version}</version>
</dependency>
<!-- http://mvnrepository.com/artifact/com.netflix.hystrix/hystrix-metrics-event-stream -->
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-metrics-event-stream</artifactId>
<version>${
hystrix-version}</version>
</dependency>
기술:
- hystrix-core : Hystrix 코어 인터페이스 패키지.
- hystrix-metrics-event-stream : 클라이언트가 여전히 연결되어있는 한 hystrix-metrics-event-stream은 계산 결과를 텍스트 / 이벤트 스트림의 형태로 클라이언트에 지속적으로 푸시합니다.
2 、 HystrixConfig.java
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class HystrixConfig {
@Bean
@HystrixProperty(name = "circuitBreaker.enabled", value = "true")
public HystrixCommandAspect hystrixCommandAspect() {
return new HystrixCommandAspect();
}
/**
* Send stream message to Hystrix-dashboard
*/
@Bean
public ServletRegistrationBean hystrixMetricsStreamServlet() {
ServletRegistrationBean registrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
registrationBean.addUrlMappings("/hystrix.stream");
return registrationBean;
}
}
3. 컨트롤러 코드
- 참조 github 소스 코드 : https://github.com/fomeiherz/spring-boot-hystrix-example
4.
브라우저를 테스트하고 http : // localhost : 7979 / hystrix-dashboard /를 방문 하고 콘솔에 스프링 부트 애플리케이션의 모니터링 주소를 입력합니다.
참고 : 서비스를 시작한 후 http : // localhost : 8080 / hystrix.stream 을 입력 한 다음 "스트림 추가"를 클릭하고 마지막으로 "스트림 모니터링"을 클릭합니다.
기술:
- hystrix2 / test1-commandKey (기본값은 메소드 이름이며 @HystrixCommand의 commandKey 속성으로 지정할 수 있습니다. 동일한 이름의 메소드가 두 개있는 경우 지정해야합니다 . )
- HystrixController2-ThreadPoolKey (기본 클래스 이름은 @HystrixCommand의 threadPoolKey 속성으로 지정할 수 있음)