一 、 Painel Hystrix
efeito:
- Monitoramento em tempo real de vários valores de indicador de cada Hystrix commandKey
- Modifique dinamicamente várias configurações por meio do monitoramento em tempo real dos painéis
painel de controle:
2. Inicie o Hystrix Dashboard
1 、 下载 standalone-hystrix-dashboard-1.5.3-all.jar
- Endereço de download: https://search.maven.org/search , digite a consulta standalone-hystrix-dashboard na caixa e faça o download.
2. Inicie o Hystrix Dashboard
java -jar -DserverPort = 7979 -DbindAddress = localhost standalone-hystrix-dashboard-1.5.3-all.jar
Nota: serverPort e bindAddress são parâmetros opcionais; se não forem adicionados, o padrão é 7979 e localhost
3. Verifique se a inicialização foi bem-sucedida
- Digite http: // localhost: 7979 / hystrix-dashboard / no navegador e a página do urso está correta.
Três, o 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>
Descrição:
- hystrix-core: pacote de interface do Hystrix core.
- hystrix-metrics-event-stream: Enquanto o cliente ainda estiver conectado, hystrix-metrics-event-stream enviará continuamente os resultados da contagem para o cliente na forma de texto / fluxo de evento.
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 do controlador
- Código-fonte do github de referência: https://github.com/fomeiherz/spring-boot-hystrix-example
4. Teste o
navegador, visite http: // localhost: 7979 / hystrix-dashboard / , insira o endereço de monitoramento do aplicativo spring-boot no console.
Observação: após iniciar o serviço, digite http: // localhost: 8080 / hystrix.stream , clique em "Adicionar fluxo" e, por fim, clique em "Monitorar fluxo".
Descrição:
- hystrix2 / test1-commandKey (O padrão é o nome do método, que pode ser especificado pelo atributo commandKey de @HystrixCommand. Deve ser especificado quando houver dois métodos com o mesmo nome )
- HystrixController2-ThreadPoolKey (o nome da classe padrão pode ser especificado pelo atributo threadPoolKey de @HystrixCommand)