在Spring Cloud中構建一個Hystrix Dashboard很是簡單,只須要下面四步:html
<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>
@EnableHystrixDashboard
,啓用Hystrix Dashboard功能。@EnableHystrixDashboard @SpringCloudApplication public class HystrixDashboardApplication { public static void main(String[] args) { SpringApplication.run(HystrixDashboardApplication.class, args); } }
application.properties
配置文件,好比:選擇一個未被佔用的端口等,此步非必須。spring.application.name=hystrix-dashboard server.port=1301
既然Hystrix Dashboard監控單實例節點須要經過訪問實例的/hystrix.stream
接口來實現,天然咱們須要爲服務實例添加這個端點,而添加該功能的步驟也一樣簡單,只須要下面兩步:java
pom.xml
中的dependencies
節點中新增spring-boot-starter-actuator
監控模塊以開啓監控相關的端點,並確保已經引入斷路器的依賴spring-cloud-starter-hystrix
:<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-hystrix</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
@EnableCircuitBreaker
或@EnableHystrix
註解,開啓了斷路器功能。到這裏已經完成了全部的配置,已啓動對「eureka-consumer-ribbon-hystrix」的監控,點擊「Monitor Stream」按鈕。spring
從如今開始,我這邊會將近期研發的springcloud微服務雲架構的搭建過程和精髓記錄下來,幫助更多有興趣研發spring cloud框架的朋友,但願能夠幫助更多的好學者。你們來一塊兒探討spring cloud架構的搭建過程及如何運用於企業項目。源碼來源架構