六:Hystrix容错监控机制

什么是微服务的容错机制

提前预设解决方案、,系统自主调节,遇到问题即时处理

什么是Hystrix

Netfix

设计原则:

  • 服务隔离机制
  • 服务降级
  • 熔断机制
  • 提供实时的监控和报警功能
  • 提供实事的配置修改功能

1.创建一个模块,配置环境

<?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>springCloud01</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>hystrix</artifactId> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</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-netflix-hystrix</artifactId>
</dependency>
</dependencies>
</project>

2.application.yml

server:
port: 8060
spring:
application:
name: hystrix
eureka:
client:
service-url:
default: http://localhost:8761/eureka
instance:
prefer-ip-address: true
feign:
hystrix:
enabled: true
management:
endpoints:
web:
exposure:
include: 'hystrix.stream'

3.创建启动类

package com.southwind;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
public class hystrixApplication {
public static void main(String[] args) {
SpringApplication.run(hystrixApplication.class,args);
}
}

4.实体类:

package com.southwind.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor; @Data
@AllArgsConstructor
@NoArgsConstructor
public class Student {
private Integer id;
private String name; }

5.接口:

package com.southwind.fegin;

import com.southwind.entity.Student;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*; import java.util.Collection; @FeignClient(value = "provider")
public interface FeignProviderClient {
@GetMapping("/provider/findall")
public Collection<Student> findall();
@GetMapping("/provider/findbyid/{id}")
public Student findbyid(@PathVariable("id") Integer id);
@PostMapping("/provider/save")
public void save(@RequestBody Student student);
@DeleteMapping("/provider/delete/{id}")
public void delete(@PathVariable("id") Integer id);
}

6.controller

package com.southwind.Handler;

import com.southwind.entity.Student;
import com.southwind.fegin.FeignProviderClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import java.util.Collection; @RestController
@RequestMapping("/hystrix")
public class FeignHandler {
@Autowired
private FeignProviderClient feignProviderClient; @GetMapping("/findall")
public Collection<Student> findall(){
return feignProviderClient.findall();
}
@GetMapping("/findbyid/{id}")
public Student findbyid(@PathVariable("id") Integer id){
return feignProviderClient.findbyid(id);
}
@PostMapping("/save")
public void save(@RequestBody Student student){
feignProviderClient.save(student);
}
@DeleteMapping("/delete")
public void deletebyid(Integer id){
feignProviderClient.delete(id);
}
}

数据监控的url

7.添加可是化页面组件

<!--        可视化依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>

8.启动类添加组件

@EnableHystrixDashboard

package com.southwind;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication
@EnableFeignClients
@EnableCircuitBreaker
@EnableHystrixDashboard
public class hystrixApplication {
public static void main(String[] args) {
SpringApplication.run(hystrixApplication.class,args);
}
}

http://localhost:8060/hystrix 可视化界面url

Hystrix容错监控机制的更多相关文章

  1. Spring Cloud08: Hystrix 容错机制与数据监控

    一.概述 容错机制是指的是在一个分布式系统中,每个微服务之间是相互调用的,并且他们之间相互依赖,而实际的运行情况中,可能会因为各种原因导致某个微服务不可用,那么依赖于这个微服务的其他微服务就可能出现响 ...

  2. 容错保护机制:Spring Cloud Hystrix

    最近在学习Spring Cloud的知识,现将容错保护机制Spring Cloud Hystrix 的相关知识笔记整理如下.[采用 oneNote格式排版]

  3. (四)Hystrix容错保护

    Feign默认是整合了Ribbon和Hystrix这两个框架,所以代码我们在上一篇的基础上进行修改,启动Eureka,service-hello,Feign 所谓的熔断机制和日常生活中见到电路保险丝是 ...

  4. SpringCloud之Hystrix容错保护原理及配置

    1 什么是灾难性雪崩效应? 如下图的过程所示,灾难性雪崩形成原因就大致如此: 造成灾难性雪崩效应的原因,可以简单归结为下述三种: 服务提供者不可用.如:硬件故障.程序BUG.缓存击穿.并发请求量过大等 ...

  5. SpringCloud系列十七:Hystrix的监控

    1. 回顾 上文讲解了使用Hystrix为Feign添加回退,并通过Fallback Factory检查回退原因以及如何为Feign客户端禁用Hystrix. 2. Hystrix的监控 除实现容错外 ...

  6. Hystrix (容错,回退,降级,缓存)

    Hystrix熔断机制就像家里的保险丝一样,若同时使用高功率的电器,就会烧坏电路,这时候保险丝自动断开就有效的保护了电路.而我们程序中也同样是这样.例如若此时数据库压力太大速度很慢,此时还有不断的请求 ...

  7. Spring Cloud 系列之 Netflix Hystrix 服务监控

    Actuator Hystrix 除了可以实现服务容错之外,还提供了近乎实时的监控功能,将服务执行结果和运行指标,请求数量成功数量等等这些状态通过 Actuator 进行收集,然后访问 /actuat ...

  8. SpringCloud Alibaba实战(9:Hystrix容错保护)

    源码地址:https://gitee.com/fighter3/eshop-project.git 持续更新中-- 在上一节我们已经使用OpenFeign完成了服务间的调用.想一下,假如我们一个服务链 ...

  9. Android Priority Job Queue (Job Manager):线程任务的容错重启机制(二)

     Android Priority Job Queue (Job Manager):线程任务的容错重启机制(二) 附录文章4简单介绍了如何启动一个后台线程任务,Android Priority J ...

  10. inotify 工具 是一种强大的、细粒度的、异步文件系统监控机制

    前言:Inotify是一种强大的.细粒度的.异步文件系统监控机制,它满足各种各样的文件监控需要,可以监控文件系统的访问属性.读写属性.权限属性.删除创建.移动等操作,也就是可以监控文件发生的一切变化. ...

随机推荐

  1. winform的TabContorl的TabPage动态添加滚动条

    关键属性 AutoScrollMinSize  private int minWidth = 800; private int minHeight = 600; List<Form> li ...

  2. (GCC) gcc编译选项 -Wl, -start-group,whole-archive,-Wl, Bstatic

    1. start-group 编译选项 假设程序x依赖三个静态库:libX1.a.libX2.a和libX3.a,而libX2.a又依赖libX1.a,libX3.a依赖libX2.a和libX1.a ...

  3. uboot引导应用程序

    uboot默认是支持执行应用程序的,就像引导内核一样,我们也可以自己写一个应用程序,让uboot启动时引导. 在uboot examples/standalone 目录下,有hello_world.c ...

  4. 关于Wegame页面空白的问题解决

    前言 前几天帮亲戚家装电脑系统,装好后发现 wegame 所有页面都不能正确加载(全部是空白页面),很神奇,在网上找了很多种解决办法都没有效果,后来不过细心的我发现360浏览器一直提示我证书不安全过期 ...

  5. 07#Web 实战:实现 GitHub 个人主页项目拖拽排序

    实现效果图 GitHub 和 Gitee 个人主页中可以对自己的项目进行拖拽排序,于是我就想自己实现一个.本随笔只是记录一下大概的实现思路,如果感兴趣的小伙伴可以通过代码和本随笔的说明去理解实现过程. ...

  6. 《HTTP权威指南》– 5.Web服务器

    Web服务器概念: 实现了HTTP和相关的TCP连接处理,负责管理Web服务器提供的资源,以及对Web服务器的配置.控制及扩展方面的管理. 各种不同的形式: 通过软件Web服务器:运行在标准的.有网络 ...

  7. 通过 CancellationToken 提高 Web 性能

    在 Web 开发中,经常会遇到这样的场景:用户发起一个请求,Web 服务器执行一些计算密集型的操作,等待结果返回给用户.这种情况下,如果用户在等待结果的过程中取消了请求,那么服务器端依然会继续执行计算 ...

  8. JavaScript冒泡排序+Vue可视化冒泡动画

    冒泡排序(Bubble Sort)算是前端最简单的算法,也是最经典的排序算法了.网上JavaScript版本的冒泡排序很多,今天用Vue实现一个动态的可视化冒泡排序. 01.JavaScript冒泡排 ...

  9. GOCVHelper图像处理算法库实例整编

        GOCVHelper主要包含图像处理.图像增强和基础文件处理三个部分.由于前两个部分较具有通用性,而且我在不同项目中都进行了反复使用,为了进一步说明类库内容,这里反过来从项目角度出发,对现有的 ...

  10. Ajax---EventLoop事件循环

    前言       JavaScript 是一门单线程执行的脚本语言.也就是说,同一时间只能做一件事情. JavaScript要运行在宿主环境中(浏览器,nodejs)下.浏览器内部有执行js代码的引擎 ...