java版spring cloud+spring boot+redis多租户社交电子商务平台(十二)断路器监控(Hystrix Dashboard)...
電子商務(wù)社交平臺源碼請加企鵝求求:一零三八七七四六二六.在我的第四篇文章斷路器講述了如何使用斷路器,并簡單的介紹了下Hystrix Dashboard組件,這篇文章更加詳細(xì)的介紹Hystrix Dashboard。
一、Hystrix Dashboard簡介
在微服務(wù)架構(gòu)中為例保證程序的可用性,防止程序出錯導(dǎo)致網(wǎng)絡(luò)阻塞,出現(xiàn)了斷路器模型。斷路器的狀況反應(yīng)了一個程序的可用性和健壯性,它是一個重要指標(biāo)。Hystrix Dashboard是作為斷路器狀態(tài)的一個組件,提供了數(shù)據(jù)監(jiān)控和友好的圖形化界面。
二、準(zhǔn)備工作
本文的的工程栗子,來源于第一篇文章的栗子,在它的基礎(chǔ)上進(jìn)行改造。
三、開始改造service-hi
在pom的工程文件引入相應(yīng)的依賴:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix-dashboard</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId></dependency>復(fù)制代碼其中,這三個依賴是必須的,缺一不可。
在程序的入口ServiceHiApplication類,加上@EnableHystrix注解開啟斷路器,這個是必須的,并且需要在程序中聲明斷路點(diǎn)HystrixCommand;加上@EnableHystrixDashboard注解,開啟HystrixDashboard
@SpringBootApplication @EnableEurekaClient @RestController @EnableHystrix @EnableHystrixDashboard public class ServiceHiApplication {public static void main(String[] args) {SpringApplication.run(ServiceHiApplication.class, args);}@Value("${server.port}")String port;@RequestMapping("/hi")@HystrixCommand(fallbackMethod = "hiError")public String home(@RequestParam String name) {return "hi "+name+",i am from port:" +port;}public String hiError(String name) {return "hi,"+name+",sorry,error!";} }復(fù)制代碼運(yùn)行程序: 依次開啟eureka-server 和service-hi.
spring cloud b2b2c電子商務(wù)社交平臺源碼請加企鵝求求:一零三八七七四六二六
轉(zhuǎn)載于:https://juejin.im/post/5cda888851882568666dfbc3
總結(jié)
以上是生活随笔為你收集整理的java版spring cloud+spring boot+redis多租户社交电子商务平台(十二)断路器监控(Hystrix Dashboard)...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux 开机文件系统发生错误
- 下一篇: Android开发中遇到的问题(二)——