广告
返回顶部
首页 > 资讯 > 精选 >Spring Cloud 关于:Spring Cloud Netflix Hystrix
  • 649
分享到

Spring Cloud 关于:Spring Cloud Netflix Hystrix

2023-06-02 16:06:37 649人浏览 安东尼
摘要

  服务短路(CircuitBreaker)  QPS:Query Per Second  TPS:Transaction Per Second  QPS:经过全链路压测,计算单机极限QPS,集群QPS=单机PQS*集群机器数量*可靠性比率

  服务短路(CircuitBreaker)

  QPS:Query Per Second

  TPS:Transaction Per Second

  QPS:经过全链路压测,计算单机极限QPS,集群QPS=单机PQS*集群机器数量*可靠性比率

  全链路压测,除了压极限QPS,还有错误数量

  全链路:一个完整的业务流程操作

  jmeter:可调整型比较灵活

  spring cloud Hystrix Client

  官网:https://GitHub.com/Netflix/Hystrix

  Reactive Java框架

  java9 Flow api

  Reactor

  RxJava(Reactive X)

  激活Hystrix

  通过@EnableHystrix激活

  配置信息wiki:Https//github.com/Netflix/Hystrix/wiki/Configuration

  Hystrix

  1. 注解方式

  @HystrixCommand(defaultFallback= "errorContent",commandProperties =

  {@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value= "100")})

  @GetMapping("/user/count")

  public String userCount() throws InterruptedException {

  Random random = new Random();

  int nextInt = random.nextInt(200);

  System.out.println("random time > "+nextInt);

  Thread.sleep(nextInt);

  return userService.userCount();

  }

  public String errorContent() {

  System.out.println("超时了");

  return "-1";

  }

  2. 编程方式

  @GetMapping("/user/count2")

  public String userCount2() {

  return new MyHystrixCommand().execute();

  }

  private class MyHystrixCommand extends com.netflix.hystrix.HystrixCommand{

  protected MyHystrixCommand() {

  super(HystrixCommandGroupKey.Factory.asKey(""), 100);

  }

  @Override

  protected String run() throws Exception {

  Random random = new Random();

  int nextInt = random.nextInt(200);

  System.out.println("random time > "+nextInt);

  Thread.sleep(nextInt);

  return "OK";

  }

  @Override

  protected String getFallback() {

  return UserServiceProviderRestApiController.this.errorContent();

  }

  }

  对比其他Java执行方式:

  Feature

  public class FutrueDemo {

  public static void main(String[] args) {

  Random random = new Random();

  ExecutorService service = Executors.newFixedThreadPool(1);

  Future futrue = service.submit(() -> {

  int value = random.nextInt(200);

  System.out.print("睡眠"+value+"ms.");

  Thread.sleep(value);

  return "OK";

  });

  try {

  futrue.get(100,TimeUnit.MILLISECONDS);

  }catch (Exception e) {

  System.out.println("超时保护...");

  }

  service.shutdown();

  }

  }

  Health Endpoint (/actuator/health)

  {

  "status": "UP",

  "details": {

  "diskSpace": {

  "status": "UP",

  "details": {

  "total": 140382552064,

  "free": 7376781312,

  "threshold": 10485760

  }

  },

  "refreshScope": {

  "status": "UP"

  },

  "discoveryComposite": {

  "status": "UP",

  "details": {

  "discoveryClient": {

  "status": "UP",

  "details": {

  "services": ["user-service-consumer", "user-service-provider", "eureka-server"]

  }

  },

  "eureka": {

  "description": "Remote status from Eureka server",

  "status": "UP",

  "details": {

  "applications": {

  "USER-SERVICE-CONSUMER": 1,

  "EUREKA-SERVER": 2,

  "USER-SERVICE-PROVIDER": 2

  }

  }

  }

  }

  },

  "hystrix": {

  "status": "UP"

  }

  }

  }

  激活熔断保护无锡妇科医院排行 http://www.0510bhyy.com/

  @EnableCircuitBreaker 激活:@EnableHystrix + spring Cloud功能

  @EnableHystrix 激活,没有一些Spring Cloud功能,如 /hystrix.stream

  hystrix Endpoint(/actuator/hystrix.stream)

  data: {

  "type": "HystrixCommand",

  "name": "MyHystrixCommand",

  "group": "",

  "currentTime": 1563720628038,

  "isCircuitBreakerOpen": false,

  "errorPercentage": 50,

  "errorCount": 2,

  "requestCount": 4,

  "rollinGCountBadRequests": 0,

  "rollingCountCollapsedRequests": 0,

  "rollingCountEmit": 0,

  "rollingCountExceptionsThrown": 0,

  "rollingCountFailure": 0,

  "rollingCountFallbackEmit": 0,

  "rollingCountFallbackFailure": 0,

  "rollingCountFallbackMissing": 0,

  "rollingCountFallbackRejection": 0,

  "rollingCountFallbackSuccess": 1,

  "rollingCountResponsesFromCache": 0,

  "rollingCountSemaphoreRejected": 0,

  "rollingCountShortCircuited": 0,

  "rollingCountSuccess": 2,

  "rollingCountThreadPoolRejected": 0,

  "rollingCountTimeout": 1,

  "currentConcurrentExecutionCount": 0,

  "rollingMaxConcurrentExecutionCount": 1,

  "latencyExecute_mean": 0,

  "latencyExecute": {

  "0": 0,

  "25": 0,

  "50": 0,

  "75": 0,

  "90": 0,

  "95": 0,

  "99": 0,

  "99.5": 0,

  "100": 0

  },

  "latencyTotal_mean": 0,

  "latencyTotal": {

  "0": 0,

  "25": 0,

  "50": 0,

  "75": 0,

  "90": 0,

  "95": 0,

  "99": 0,

  "99.5": 0,

  "100": 0

  },

  "propertyValue_circuitBreakerRequestVolumeThreshold": 20,

  "propertyValue_circuitBreakerSleepWindowInMilliseconds": 5000,

  "propertyValue_circuitBreakerErrorThresholdPercentage": 50,

  "propertyValue_circuitBreakerForceOpen": false,

  "propertyValue_circuitBreakerForceClosed": false,

  "propertyValue_circuitBreakerEnabled": true,

  "propertyValue_executionIsolationStrategy": "THREAD",

  "propertyValue_executionIsolationThreadTimeoutInMilliseconds": 100,

  "propertyValue_executionTimeoutInMilliseconds": 100,

  "propertyValue_executionIsolationThreadInterruptOnTimeout": true,

  "propertyValue_executionIsolationThreadPoolKeyOverride": null,

  "propertyValue_executionIsolationSemaphoreMaxConcurrentRequests": 10,

  "propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests": 10,

  "propertyValue_metricsRollingStatisticalWindowInMilliseconds": 10000,

  "propertyValue_requestCacheEnabled": true,

  "propertyValue_requestLogEnabled": true,

  "reportingHosts": 1,

  "threadPool": ""

  }

  Spring Cloud Hystrix Dashboard

  使用@EnableHystrixDashboard激活

  @SpringBootApplication

  @EnableHystrixDashboard

  public class SpringCloudHystrixDashboardApplication {

  public static void main(String[] args) {

  SpringApplication.run(SpringCloudHystrixDashboardApplication.class, args);

  }

  }

--结束END--

本文标题: Spring Cloud 关于:Spring Cloud Netflix Hystrix

本文链接: https://www.lsjlt.com/news/230575.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Spring Cloud 关于:Spring Cloud Netflix Hystrix
      服务短路(CircuitBreaker)  QPS:Query Per Second  TPS:Transaction Per Second  QPS:经过全链路压测,计算单机极限QPS,集群QPS=单机PQS*集群机器数量*可靠性比率...
    99+
    2023-06-02
  • 我是如何替换Spring Cloud Netflix的?
    作者:Piotr Mińkowski,“Mastering Spring Cloud”一书作者原文链接:https://dzone.com/articles/microservices-with-spring-cloud-alibaba如果...
    99+
    2023-06-05
  • spring cloud gateway集成hystrix实战篇
    spring cloud gateway集成hystrix 本文主要研究一下spring cloud gateway如何集成hystrix maven <dependenc...
    99+
    2022-11-12
  • spring cloud gateway集成hystrix的方法
    本篇内容介绍了“spring cloud gateway集成hystrix的方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!spring ...
    99+
    2023-06-20
  • Spring Boot、Spring Cloud与Spring Cloud Alibaba版本对应关系
    一、前言 在搭建SpringCloud项目环境架构的时候,经常需要选择SpringBoot和SpringCloud进行兼容的版本号。因此,对于选择SpringBoot版本与SpringCloud版本的...
    99+
    2023-10-09
    spring boot spring cloud java
  • Spring Cloud Hystrix的基本用法大全
    目录1. Hystrix的简单使用1.1 服务降级1.2 服务熔断2. OpenFeign集成Hystrix3. Hystrix熔断原理3.1 熔断状态3.2 熔断的工作原理4. 代...
    99+
    2022-11-13
  • 关于Spring Cloud的核心特性
    SOA和微服务的区别 其实服务化架构已经可以解决大部分企业的需求了,那么我们为什么要研究微服务呢?先说说它们的区别; 微服务架构强调业务系统需要彻底的组件化和服务化,一个组件就是一个产品,可以独立对外提供服务微服务不再强...
    99+
    2023-06-05
  • Spring Cloud中熔断器Hystrix有什么用
    这篇文章主要为大家展示了“Spring Cloud中熔断器Hystrix有什么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Spring Cloud中熔断器Hystrix有什么用”这篇文章吧。...
    99+
    2023-06-19
  • Spring Cloud中Hystrix的请求合并方法
    本篇内容介绍了“Spring Cloud中Hystrix的请求合并方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!服务提供者接口我需在在服...
    99+
    2023-06-19
  • 浅谈Spring Cloud Netflix-Ribbon灰度方案之Zuul网关灰度
    Eureka默认集成了Ribbon,所以Ribbon的灰度实现原理就是借助服务注册到Eureka中的eureka.instance.metadata-map的内容来进行匹配的。 Zu...
    99+
    2022-11-12
  • 了解Spring Cloud Netflix-Ribbon灰度方案之Zuul网关灰度
    这篇文章主要讲解了“了解Spring Cloud Netflix-Ribbon灰度方案之Zuul网关灰度”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“了解Spring Cloud Netfl...
    99+
    2023-06-14
  • Spring Cloud中的断路器Hystrix怎么使用
    本篇内容介绍了“Spring Cloud中的断路器Hystrix怎么使用”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!首先我们分别启动服务注...
    99+
    2023-06-19
  • 关于Spring Cloud健康检查的陷阱
    SpringCloud健康检查的陷阱 健康检查 基于Spring Boot Actuator的健康检查是Spring Cloud微服务的必备组件,用来确保我们的服务是否可用。 引入 ...
    99+
    2022-11-12
  • spring cloud分布式微服务:Spring Cloud Config
    Spring Cloud Config是Spring Cloud团队创建的一个全新项目,用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,它分为服务端与客户端两个部分。其中服务端也称为分布式配置中心,它是一个独立的微服务应用...
    99+
    2023-06-05
  • Spring Cloud Gateway 网关尝鲜
    Gateway 介绍Spring Cloud Gateway是Spring官方基于Spring 5.0,Spring Boot 2.0和Project Reactor等技术开发的网关,Spring Cloud Gateway旨在为微服务架构...
    99+
    2023-06-03
  • Spring Boot跟Spring Cloud是什么关系
    这篇文章主要讲解了“Spring Boot跟Spring Cloud是什么关系”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Spring Boot跟Spring Cloud是什么关系”吧!S...
    99+
    2023-06-05
  • spring cloud gateway集成hystrix全局断路器操作
    gateway集成hystrix全局断路器 pom.xml添加依赖 <dependency> <groupId>org.springframework.c...
    99+
    2022-11-12
  • Spring Cloud中怎么自定义Hystrix请求命令
    Spring Cloud中怎么自定义Hystrix请求命令,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。自定义HystrixCommand我们除了使用@Hyst...
    99+
    2023-06-19
  • Spring Cloud中Hystrix的请求缓存怎么实现
    本篇内容介绍了“Spring Cloud中Hystrix的请求缓存怎么实现”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!通过方法重载开启缓存...
    99+
    2023-06-19
  • Spring Cloud中如何使用Hystrix实现断路器
    这篇文章主要介绍了Spring Cloud中如何使用Hystrix实现断路器的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Spring Cloud中如何使用Hystrix实现断路器文章都会有所收获,下面我们一起...
    99+
    2023-06-04
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作