博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
第十篇: Hystrix Dashboard(Hoxton版本)
阅读量:4182 次
发布时间:2019-05-26

本文共 4232 字,大约阅读时间需要 14 分钟。

新建hystrix-dashboard-service-hi模块

pom文件

4.0.0
com.xiaobu
springcloud-demo
0.0.1-SNAPSHOT
hystrix-dashboard-service-hi
0.0.1-SNAPSHOT
hystrix-dashboard-service-hi
hystrix-dashboard-service-hi project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-netflix-hystrix
org.springframework.cloud
spring-cloud-starter-netflix-hystrix-dashboard
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin

application.properties

eureka.client.service-url.defaultZone=http://localhost:8001/eureka/server.port=8010spring.application.name=hystrix-dashboard-service-hi# 下面的必须配置 不然访问https://hystrix-app:port/actuator/hystrix.stream 会报404management.endpoints.web.exposure.include=*management.endpoints.web.cors.allowed-origins=*management.endpoints.web.cors.allowed-methods=*

HystrixDashboardServiceHiApplication.java

package com.xiaobu;import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;import lombok.extern.slf4j.Slf4j;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.CommandLineRunner;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;import org.springframework.cloud.netflix.hystrix.EnableHystrix;import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;/** * @author xiaobu */@SpringBootApplication@EnableEurekaClient@EnableDiscoveryClient@RestController@EnableHystrix@EnableHystrixDashboard@EnableCircuitBreaker@Slf4jpublic class HystrixDashboardServiceHiApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run( HystrixDashboardServiceHiApplication.class, args ); } @Value("${server.port}") String port; @RequestMapping("/hi") @HystrixCommand(fallbackMethod = "hiError") public String home(@RequestParam(value = "name", defaultValue = "admin") String name) {
return "hi " + name + " ,i am from port:" + port; } public String hiError(String name) {
return "hi,"+name+",sorry,error!"; } @Override public void run(String... args) throws Exception {
log.info("服务hystrix-dashboard-service-hi在端口:{},启动成功....",port); }}

运行程序: 依次开启eureka-server(与第一章相同)和hystrix-dashboard-service-hi.

访问 http://localhost:8010/hi

然后访问 http://localhost:8010/actuator/hystrix.stream

1611108738(1).jpg

访问 http://localhost:8010/hystrix

1611108888(1).jpg

依次输入

http://localhost:8010/actuator/hystrix.stream 2000 admin

再次访问 http://localhost:8010/hystrix 出现如下示图

1611108981(1).jpg

转载地址:http://fkgai.baihongyu.com/

你可能感兴趣的文章
一个员工的离职成本到底有多恐怖!
查看>>
微软骂人:请勿TM关闭......
查看>>
B站python+数据分析精华汇总!速领,免费,一会删!
查看>>
一个中科大差生的8年程序员工作总结
查看>>
新功能!微信可以开“小号”了
查看>>
墙裂推荐!一款 VM 大规模集群管理工具
查看>>
知乎万赞:计算机应届生月薪大多是多少?
查看>>
试用期没过,因在公司上了1024网站...
查看>>
终于有人把如何精通C++讲明白了!
查看>>
我的天!史上最强的摸鱼网站!!!
查看>>
新款电脑,真香啊!!!
查看>>
为什么我劝你不要太把领导当回事?
查看>>
牛逼至极!用这个神器看代码太舒服了
查看>>
信息量过大,8h删!
查看>>
奉劝那些想把编程学好的人
查看>>
如果诸葛亮用C++写出师表。。。。
查看>>
线上jar包里,竟然藏有小电影
查看>>
火爆国外的Python教程,终于迎来了汉化版!
查看>>
VS Code 真的会一统江湖吗?
查看>>
百度网盘这个版本绝了,简洁无广告,速度还快
查看>>