SpringCloud分布式微服务b2b2c电子商务中​怎么用turbine+hystrix-dashboard监听两个消费者服务-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

SpringCloud分布式微服务b2b2c电子商务中​怎么用turbine+hystrix-dashboard监听两个消费者服务

这篇文章主要介绍SpringCloud分布式微服务b2b2c电子商务中怎么用turbine+hystrix-dashboard监听两个消费者服务,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

创新互联专注于松山企业网站建设,成都响应式网站建设,电子商务商城网站建设。松山网站建设公司,为松山等地区提供建站服务。全流程按需规划网站,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

怎么用turbine+hystrix-dashboard监听两个消费者服务

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

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

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

SpringCloud分布式微服务b2b2c电子商务中​怎么用turbine+hystrix-dashboard监听两个消费者服务

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:7788
server:
  port: 8010
eureka:
  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:
  #oauth3:
   # 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;
 
@RestController
public 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;
  }
}

以上是“SpringCloud分布式微服务b2b2c电子商务中怎么用turbine+hystrix-dashboard监听两个消费者服务”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!


本文题目:SpringCloud分布式微服务b2b2c电子商务中​怎么用turbine+hystrix-dashboard监听两个消费者服务
网址分享:http://kswsj.cn/article/jsshoh.html

其他资讯