博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java B2B2C springmvc mybatis多租户电子商城系统-docker-hystrix-dashboard-turbine(九)
阅读量:6954 次
发布时间:2019-06-27

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

简介

Hystrix的主要优点之一是它收集关于每个HystrixCommand的一套指标。Hystrix仪表板以有效的方式显示每个断路器的运行状况,通过Hystrix Dashboard我们可以在直观地看到各Hystrix Command的断路器是否打开,请求响应时间, 请求失败率,请求超时个数等等数据。但是只使用Hystrix Dashboard的话, 你只能看到单个应用内的服务信息, 这明显不够. 我们需要一个工具能让我们汇总系统内多个服务的数据并显示到Hystrix Dashboard上, 这个工具就是Turbine,这节我们讨论一下,怎么用turbine+hystrix-dashboard监听两个消费者服务

一、监听模块microservice-consumer-movie-feign-with-hystrix断路器的运行状况

二、监听模块microservice-consumer-movie-ribbon-with-hystrix1断路器的运行状况

2.1、创建模块microservice-consumer-movie-ribbon-with-hystrix1

项目结构如下:

image

2.2、pom.xml文件

microservice-spring-cloud
com.jacky
1.0-SNAPSHOT
4.0.0
microservice-consumer-movie-ribbon-with-hystrix1
jar
UTF-8
UTF-8
1.8
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-eureka
org.springframework.boot
spring-boot-starter-actuator
org.springframework.cloud
spring-cloud-starter-hystrix
org.springframework.cloud
spring-cloud-starter-zipkin
com.spotify
docker-maven-plugin
build-image
install
build
http://192.168.6.130:5678
true
${docker.repostory}/${docker.image.prefix}/${project.artifactId}:${project.version}
java:openjdk-8-jdk-alpine
["java", "-jar", "/${project.build.finalName}.jar"]
/
${project.build.directory}
${project.build.finalName}.jar

2.3、配置文件application.yml

spring:  application:    name: microservice-consumer-movie-ribbon-with-hystrix1  sleuth:    sampler:      percentage: 1.0  #zipkin:    #base-url: http://localhost:7788server:  port: 8010eureka:  client:    healthcheck:      enabled: true    serviceUrl:      defaultZone: http://jacky:admin@peer1:8761/eureka/,http://jacky:admin@peer2:8762/eureka/,http://jacky:admin@peer3:8763/eureka/  instance:    prefer-ip-address: true    instance-id: ${spring.application.name}:${spring.cloud.client.ipAddress}:${spring.application.instance_id:${server.port}}hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000#security:  #oauth2:   # resource:    #  id: microservice-consumer-movie-ribbon-with-hystrix1     # user-info-uri: http://localhost:9999/uaa/user      #prefer-token-info: false

2.4、实体类User.java

package com.jacky.cloud.entity; import java.math.BigDecimal; public class User {  private Long id;   private String username;   private String name;   private Short age;   private BigDecimal balance;   public Long getId() {    return this.id;  }   public void setId(Long id) {    this.id = id;  }   public String getUsername() {    return this.username;  }   public void setUsername(String username) {    this.username = username;  }   public String getName() {    return this.name;  }   public void setName(String name) {    this.name = name;  }   public Short getAge() {    return this.age;  }   public void setAge(Short age) {    this.age = age;  }   public BigDecimal getBalance() {    return this.balance;  }   public void setBalance(BigDecimal balance) {    this.balance = balance;  } }

2.5、控制层MovieController.java

package com.jacky.cloud.controller; import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.client.RestTemplate; import com.jacky.cloud.entity.User;import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; @RestControllerpublic class MovieController {  @Autowired  private RestTemplate restTemplate;   @GetMapping("/movie/{id}")  @HystrixCommand(groupKey="UserGroup1", commandKey = "findUserByIdCommand1",commandProperties = {          @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000"),          @HystrixProperty(name = "execution.timeout.enabled", value = "false")},fallbackMethod = "findByIdFallback")  public User findById(@PathVariable Long id) {    return this.restTemplate.getForObject("http://microservice-provider-user/simple/" + id, User.class);  }   /**   * fallback方法   * @param id   * @return     */  public User findByIdFallback(Long id) {    User user = new User();    user.setId(5L);    return user;  }}

源码结构

image

Spring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码

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

你可能感兴趣的文章
Binary Tree Maximum Path Sum leetcode
查看>>
一天一点linux(8):ubuntu安装后ssh无法连接怎么解决?
查看>>
Substring with Concatenation of All Words
查看>>
搭建AngualarJS开发环境
查看>>
我的前端开发准则
查看>>
如何助力企业 APP 在竞争中占据先机?
查看>>
[译]在 React.js 中使用 ES6+
查看>>
协同过滤算法
查看>>
移动端原生JS实现手指跟随的触控滑动
查看>>
js初级应用之svg实现环形进度条
查看>>
ASP.NET CORE下运行CMD命令
查看>>
requests库核心API源码分析
查看>>
C语言程序员不会告诉你的14个工具和插件 | 收藏 ...
查看>>
2019年人工智能硬件与应用大趋势
查看>>
2018 FDA获批医疗器械盘点,政策红利能否继续?
查看>>
Git协同工作流介绍
查看>>
语音识别实时对比(百度收费 VS SpeechTexter免费)
查看>>
2018智能汽车盘点,新旧造车势力的智能化PK
查看>>
阿里云服务器的配置及搭建教程
查看>>
书籍:python游戏编码 Coding Games in Python - 2018
查看>>