一、Hystrixダッシュボード
効果:
- 各Hystrixコマンドキーのさまざまなインジケーター値のリアルタイム監視
- ダッシュボードのリアルタイム監視を通じて、さまざまな構成を動的に変更します
ダッシュボード:
2.Hystrixダッシュボードを起動します
1、下取スタンドアロン-hystrix-dashboard-1.5.3-all.jar
- ダウンロードアドレス:https://search.maven.org/search、ボックスにstandalone-hystrix-dashboardクエリを入力して、ダウンロードします。
2.Hystrixダッシュボードを起動します
java -jar -DserverPort = 7979 -DbindAddress = localhostスタンドアロン-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 /にアクセスし、コンソールにSpring -Bootアプリケーションの監視アドレスを入力します。
注:サービスの開始後、http:// localhost:8080 / hystrix.streamと入力し、[ストリームの追加]をクリックして、最後に[ストリームの監視]をクリックします。
説明:
- hystrix2 / test1-commandKey(デフォルトはメソッド名で、@ HystrixCommandの属性commandKeyで指定できます。同じ名前のメソッドが2つある場合は、指定する必要があります)
- HystrixController2-ThreadPoolKey(デフォルトのクラス名は@HystrixCommandの属性threadPoolKeyで指定できます)