一 、 Hystrix-Dashboard
bewirken:
- Echtzeitüberwachung verschiedener Indikatorwerte jedes Hystrix-Befehlsschlüssels
- Ändern Sie verschiedene Konfigurationen dynamisch durch Echtzeitüberwachung von Dashboards
Instrumententafel:
2. Starten Sie das Hystrix Dashboard
1 al 下载 Standalone-Hystrix-Dashboard-1.5.3-all.jar
- Laden Sie die Adresse herunter: https://search.maven.org/search , geben Sie die Standalone-Hystrix-Dashboard-Abfrage in das Feld ein und laden Sie sie herunter.
2. Starten Sie das Hystrix Dashboard
java -jar -DserverPort = 7979 -DbindAddress = localhost Standalone-Hystrix-Dashboard-1.5.3-all.jar
Hinweis: serverPort und bindAddress sind optionale Parameter. Wenn sie nicht hinzugefügt werden, ist der Standardwert 7979 und localhost
3. Überprüfen Sie, ob der Start erfolgreich ist
- Geben Sie http: // localhost: 7979 / hystrix-dashboard / in den Browser ein und die Bärenseite ist korrekt.
Drei, der Code
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>
Beschreibung:
- Hystrix-Core: Hystrix-Core-Schnittstellenpaket.
- Hystrix-Metrics-Event-Stream: Solange der Client noch verbunden ist, sendet der Hystrix-Metrics-Event-Stream die Zählergebnisse kontinuierlich in Form von Text / Event-Stream an den Client.
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. Controller-Code
- Referenz-Github-Quellcode: https://github.com/fomeiherz/spring-boot-hystrix-example
4. Testen Sie den
Browser unter http: // localhost: 7979 / hystrix-dashboard / und geben Sie die Überwachungsadresse der Spring-Boot-Anwendung in die Konsole ein.
Hinweis: Geben Sie nach dem Starten des Dienstes http: // localhost: 8080 / hystrix.stream ein , klicken Sie auf "Stream hinzufügen " und schließlich auf "Stream überwachen".
Beschreibung:
- hystrix2 / test1-commandKey (Der Standardwert ist der Methodenname, der durch das Attribut commandKey von @HystrixCommand angegeben werden kann. Er muss angegeben werden, wenn zwei Methoden mit demselben Namen vorhanden sind. )
- HystrixController2-ThreadPoolKey (der Standardklassenname kann durch das Attribut threadPoolKey von @HystrixCommand angegeben werden)