El disyuntor supervisa el uso del tablero de Hystrix

一 、 Panel de Hystrix

efecto:
  • Monitoreo en tiempo real de varios valores de indicador de cada comando de Hystrix
  • Modifique dinámicamente varias configuraciones a través del monitoreo en tiempo real de los paneles
tablero:

Alt

2. Inicie el panel de Hystrix

1 、 下载 independiente-hystrix-dashboard-1.5.3-all.jar

2. Inicie el panel de Hystrix

java -jar -DserverPort = 7979 -DbindAddress = localhost standalone-hystrix-dashboard-1.5.3-all.jar

Nota: serverPort y bindAddress son parámetros opcionales, si no se agregan, el valor predeterminado es 7979 y localhost

3. Verifique si la puesta en marcha es exitosa

  • Ingrese http: // localhost: 7979 / hystrix-dashboard / en el navegador y la página del oso es correcta.

Tres, el código

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>

Descripción:

  • hystrix-core: paquete de interfaz principal de Hystrix.
  • hystrix-metrics-event-stream: mientras el cliente aún esté conectado, hystrix-metrics-event-stream enviará continuamente los resultados del recuento al cliente en forma de texto / 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. Código del controlador

4. Pruebe el
navegador, visite http: // localhost: 7979 / hystrix-dashboard / , ingrese la dirección de monitoreo de la aplicación spring-boot en la consola.
Alt
Nota: Después de iniciar el servicio, ingrese http: // localhost: 8080 / hystrix.stream , luego haga clic en "Agregar transmisión " y finalmente haga clic en "Monitorear transmisión".

Alt

Descripción:

  • hystrix2 / test1-commandKey (El valor predeterminado es el nombre del método, que se puede especificar mediante el atributo commandKey de @HystrixCommand. Debe especificarse cuando hay dos métodos con el mismo nombre )
  • HystrixController2-ThreadPoolKey (el nombre de clase predeterminado se puede especificar mediante el atributo threadPoolKey de @HystrixCommand)

Supongo que te gusta

Origin blog.csdn.net/fomeiherz/article/details/89315148
Recomendado
Clasificación