文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

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

2023-06-05 04:23

关注

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

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

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

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

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

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

2、pom.xml文件

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0"         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">    <parent>        <artifactId>microservice-spring-cloud</artifactId>        <groupId>com.jacky</groupId>        <version>1.0-SNAPSHOT</version>    </parent>    <modelVersion>4.0.0</modelVersion>     <artifactId>microservice-consumer-movie-ribbon-with-hystrix1</artifactId>    <packaging>jar</packaging>     <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>        <java.version>1.8</java.version>    </properties>     <dependencies>        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>         <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-eureka</artifactId>        </dependency>         <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-actuator</artifactId>        </dependency>         <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-hystrix</artifactId>        </dependency>        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-zipkin</artifactId>        </dependency>    </dependencies>    <build>        <plugins>            <plugin>                <groupId>com.spotify</groupId>                <artifactId>docker-maven-plugin</artifactId>                <executions>                    <!--设置在执行maven 的install时构建镜像-->                    <execution>                        <id>build-image</id>                        <phase>install</phase>                        <goals>                            <goal>build</goal>                        </goals>                    </execution>                </executions>                <configuration>                    <!--安装了docker的主机,并且打开了api remote接口设置-->                    <dockerHost>http://192.168.6.130:5678</dockerHost>                    <pushImage>true</pushImage><!--设置上传镜像到私有仓库,需要docker设置指定私有仓库地址-->                    <!--镜像名称-->                    <imageName>${docker.repostory}/${docker.image.prefix}/${project.artifactId}:${project.version}</imageName>                    <!--镜像的基础版本-->                    <baseImage>java:openjdk-8-jdk-alpine</baseImage>                    <!--镜像启动参数-->                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>                    <resources>                        <resource>                            <targetPath>/</targetPath>                            <directory>${project.build.directory}</directory>                            <include>${project.build.finalName}.jar</include>                        </resource>                    </resources>                </configuration>            </plugin>        </plugins>    </build></project>

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:  #oauth3:   # resource:    #  id: microservice-consumer-movie-ribbon-with-hystrix1     # user-info-uri: http://localhost:9999/uaa/user      #prefer-token-info: false

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;  } }

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);  }     public User findByIdFallback(Long id) {    User user = new User();    user.setId(5L);    return user;  }}

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

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯