Building a Hystrix dashboard in spring cloud is very simple and requires only the following four steps:
- Create a standard spring boot project named: Hystrix-dashboard.
- Edit Pom.xml, depending on the content as follows:
1234567891011121314151617181920 |
<parent> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-parent</artifactid> <version>dalston.sr1</version> <relativepath/> </parent> <dependencies> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-hystrix</artifactid> </dependency> <dependency> <groupid>org.springframework.cloud</groupid> <artifactid>spring-cloud-starter-hystrix-dashboard</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-actuator</artifactid> </dependency> </dependencies> |
- To apply the main class plus
@EnableHystrixDashboard
, enable the Hystrix dashboard feature.
1234567 |
@EnableHystrixDashboard @SpringCloudApplication public class hystrixdashboardapplication {public static void Main (string[] args) { Springapplication.run (Hystrixdashboardapplication.class, args);}} |
- Modify the configuration file according to the actual situation
application.properties
, such as: Select an unoccupied port, etc., this step is not necessary.
12 |
spring.application.name=hystrix-dashboardserver.port=1301 |
Since the Hystrix dashboard monitoring Single instance node needs to be implemented by accessing the interface of the instance, /hystrix.stream
naturally we need to add this endpoint for the service instance, and the steps to add that feature are just as simple as the following two steps:
pom.xml
Add a monitoring module to the node in the service instance dependencies
spring-boot-starter-actuator
to turn on the monitoring-related endpoint and ensure that the circuit-breaker dependency has been introduced spring-cloud-starter-hystrix
:
12345678 |
<DEPENDENCY> <groupid>org.springframework.cloud</ GROUPID> <artifactid>spring-cloud-starter-hystrix</< Span class= "name" >ARTIFACTID> </ Dependency> <DEPENDENCY> <groupid>org.springframework.boot</ GROUPID> <artifactid>spring-boot-starter-actuator</< Span class= "name" >ARTIFACTID> </ Dependency> |
- Make sure that the breaker function is turned on by using or annotating the main class of the service instance
@EnableCircuitBreaker
@EnableHystrix
.
All the configurations have been completed, the "Eureka-consumer-ribbon-hystrix" monitoring has been initiated and the "Monitor Stream" button has been clicked.
From now on, I will record the process and the essence of the recently developed Springcloud micro-service cloud architecture, and help more friends who are interested in developing the Spring cloud framework, hoping to help more good scholars. Let's explore how the Spring cloud architecture is built and how it can be used in enterprise projects.
Spring Cloud builds a microservices architecture Hystrix monitoring Panel