一 、 Tableau de bord Hystrix
effet:
- Surveillance en temps réel des différentes valeurs d'indicateur de chaque commande Hystrix
- Modifier dynamiquement diverses configurations grâce à la surveillance en temps réel des tableaux de bord
tableau de bord:
2. Démarrez Hystrix Dashboard
1 、 下载 standalone-hystrix-dashboard-1.5.3-all.jar
- Adresse de téléchargement: https://search.maven.org/search , entrez la requête standalone-hystrix-dashboard dans la zone, puis téléchargez.
2. Démarrez Hystrix Dashboard
java -jar -DserverPort = 7979 -DbindAddress = localhost standalone-hystrix-dashboard-1.5.3-all.jar
Remarque: le serverPort et bindAddress sont des paramètres facultatifs, s'ils ne sont pas ajoutés, la valeur par défaut est 7979 et localhost
3. Vérifiez si le démarrage a réussi
- Entrez http: // localhost: 7979 / hystrix-dashboard / dans le navigateur et la page de l'ours est correcte.
Trois, le 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>
La description:
- hystrix-core: package d'interface de base Hystrix.
- hystrix-metrics-event-stream: tant que le client est toujours connecté, hystrix-metrics-event-stream transmettra continuellement les résultats du comptage au client sous la forme de texte / 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. Code du contrôleur
- Référence code source github: https://github.com/fomeiherz/spring-boot-hystrix-example
4. Testez le
navigateur, visitez http: // localhost: 7979 / hystrix-dashboard / , entrez l'adresse de surveillance de l'application spring-boot dans la console.
Remarque: après le démarrage du service, entrez http: // localhost: 8080 / hystrix.stream , puis cliquez sur "Ajouter un flux", et enfin sur "Surveiller le flux".
La description:
- hystrix2 / test1-commandKey (La valeur par défaut est le nom de la méthode, qui peut être spécifié par l'attribut commandKey de @HystrixCommand. Il doit être spécifié lorsqu'il existe deux méthodes portant le même nom )
- HystrixController2-ThreadPoolKey (le nom de classe par défaut peut être spécifié par l'attribut threadPoolKey de @HystrixCommand)