中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

alexa排名全球前50網(wǎng)站排名優(yōu)化方案

alexa排名全球前50網(wǎng)站,排名優(yōu)化方案,建站seo怎么賺錢,個人dw網(wǎng)頁設(shè)計這里寫目錄標(biāo)題 系列文章目錄背景一、Hystrix是什么服務(wù)雪崩服務(wù)容錯的相關(guān)概念熔斷器降級超時控制限流 二、會什么要有Hystrix三、如何使用Hystrix進行熔斷處理整體項目代碼服務(wù)提供者pom文件yml配置文件啟動類controller 服務(wù)消費者pom文件yml配置文件啟動類feignhystrixcont…

這里寫目錄標(biāo)題

  • 系列文章目錄
  • 背景
  • 一、Hystrix是什么
    • 服務(wù)雪崩
    • 服務(wù)容錯的相關(guān)概念
      • 熔斷器
      • 降級
      • 超時控制
      • 限流
  • 二、會什么要有Hystrix
  • 三、如何使用Hystrix進行熔斷處理整體
    • 項目代碼
      • 服務(wù)提供者
        • pom文件
        • yml配置文件
        • 啟動類
        • controller
      • 服務(wù)消費者
        • pom文件
        • yml配置文件
        • 啟動類
        • feign
        • hystrix
        • controller
    • 服務(wù)啟動
  • 總結(jié)

系列文章目錄

【Spring Cloud一】微服務(wù)基本知識
【Spring Cloud 三】Eureka服務(wù)注冊與服務(wù)發(fā)現(xiàn)
【Spring Cloud 四】Ribbon負載均衡
【Spring Cloud 五】OpenFeign服務(wù)調(diào)用

背景

目前開發(fā)的項目其微服務(wù)之間的熔斷處理方式使用的就是Hystrix的方式,為了更加的體會到它代碼的便捷和高效,所以博主對Hystrix進行了再次學(xué)習(xí)和實踐,加強對Hystrix的整體理解。

一、Hystrix是什么

Hystrix是Netflix開源的一款用于處理分布式系統(tǒng)故障容錯延遲容錯的工具。它提供了熔斷器的功能,能夠阻止分布式系統(tǒng)中出現(xiàn)級聯(lián)故障。

服務(wù)雪崩

如下發(fā)的圖所示:

  1. 用戶去請求A服務(wù),A服務(wù)web服務(wù)器會分配一個線程支持用戶的訪問
    A發(fā)現(xiàn)需要完成用戶的操作血藥去調(diào)用B服務(wù)。
  2. A去請求B服務(wù),B的web服務(wù)器也會分配一個線程支持A的訪問
    B發(fā)現(xiàn)需要完成A的操作需要去調(diào)用C。
  3. B去調(diào)用C但是C宕機了,B并不知道,還是一如既往的去調(diào)用C
  4. 導(dǎo)致A和B的線程都沒有回收
    但是此時又有大量請求進入A服務(wù)或者B服務(wù),當(dāng)將web容器的線程資源會被消耗完,服務(wù)就會癱瘓。服務(wù)A和服務(wù)B也就癱瘓了

這種由于一個服務(wù)出現(xiàn)故障,導(dǎo)致其余服務(wù)跟著產(chǎn)生故障,最后導(dǎo)致整個系統(tǒng)出現(xiàn)嚴(yán)重故障的現(xiàn)象就是服務(wù)雪崩。
在這里插入圖片描述

服務(wù)容錯的相關(guān)概念

服務(wù)容錯是確保系統(tǒng)在出現(xiàn)故障或異常情況繼續(xù)保持可用性的一系列技術(shù)和方法。

熔斷器

熔斷器是一種防止故障蔓延的模式,在一個系統(tǒng)中,當(dāng)其中一個服務(wù)發(fā)送故障的時候,熔斷器會中斷對該服務(wù)的請求,并返回預(yù)先設(shè)定的降級措施,從而防止對整個系統(tǒng)造成影響。

降級

降級是一種在服務(wù)發(fā)生故障時提供的備選響應(yīng)的策略,確保用戶在服務(wù)故障時依然能夠得到響應(yīng)。

超時控制

一個服務(wù)的響應(yīng)時間可能因網(wǎng)絡(luò)、資源等問題而增加。超時控制是指在發(fā)起請求后設(shè)置一個合理的超時時間,如果服務(wù)在規(guī)定時間內(nèi)沒有響應(yīng),就人物請求超時,并根據(jù)預(yù)定策略進行處理,如降級響應(yīng)。

限流

限流是一種用于控制系統(tǒng)訪問速率的策略,防止過多的請求同時涌入系統(tǒng),導(dǎo)致系統(tǒng)過載而崩潰。通過限制請求的速率,可以保證系統(tǒng)在承受能力范圍內(nèi)穩(wěn)定運行。

二、會什么要有Hystrix

為什么要有Hystrix,Hystrix解決了什么問題?

Hystrix在分布式系統(tǒng)中解決了故障容錯、延遲容錯、請求合并與緩存、實時監(jiān)控、異常處理等問題,保證系統(tǒng)在出現(xiàn)故障是一眼能夠保持可用性,防止級聯(lián)故障的發(fā)生。

三、如何使用Hystrix進行熔斷處理整體

整個系統(tǒng)中有三個服務(wù),Eureka服務(wù),一個服務(wù)提供者,一個服務(wù)消費者

在這里插入圖片描述
如何搭建Eurka服務(wù)可以訪問這篇博客【Spring Cloud 三】Eureka服務(wù)注冊與服務(wù)發(fā)現(xiàn)


補充:Hystrix是通過隔離服務(wù)的訪問點阻止級聯(lián)故障(熔斷器Circuit Breaker),并提供了故障的解決方案(服務(wù)降級FallBack),從而提高整個分布式系統(tǒng)的高可用。

項目代碼

服務(wù)提供者

pom文件

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.12.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.wangwei</groupId><artifactId>rent-car-service</artifactId><version>0.0.1-SNAPSHOT</version><name>rent-car-service</name><description>rent-car-service</description><properties><java.version>8</java.version><spring-cloud.version>Hoxton.SR12</spring-cloud.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-netflix-eureka-client</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

yml配置文件

server:port: 8080spring:application:name: rent-car-service
eureka:client:service-url: defaultZone: http://localhost:8761/eurekaregister-with-eureka: true #設(shè)置為fasle 不往eureka-server注冊fetch-registry: true #應(yīng)用是否拉取服務(wù)列表到本地registry-fetch-interval-seconds: 10 #為了緩解服務(wù)列表的臟讀問題,時間越短臟讀越少 性能相應(yīng)的消耗回答instance: #實例的配置instance-id: ${eureka.instance.hostname}:${spring.application.name}:${server.port}hostname: localhost #主機名稱或者服務(wù)ipprefer-ip-address: true #以ip的形式顯示具體的服務(wù)信息lease-renewal-interval-in-seconds: 10 #服務(wù)實例的續(xù)約時間間隔

啟動類

@SpringBootApplication
@EnableEurekaClient
public class RentCarServiceApplication {public static void main(String[] args) {SpringApplication.run(RentCarServiceApplication.class, args);}}

controller

@RestController
public class RentCarController {@GetMapping("rent")public String rent(){return "租車成功";}
}

服務(wù)消費者

pom文件

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.12.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.wangwei</groupId><artifactId>customer-service</artifactId><version>0.0.1-SNAPSHOT</version><name>customer-service</name><description>customer-service</description><properties><java.version>8</java.version><spring-cloud.version>Hoxton.SR12</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-hystrix</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><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-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

yml配置文件


server:port: 8081spring:application:name: customer-service
eureka:client:service-url:defaultZone: http://localhost:8761/eurekaregister-with-eureka: true #設(shè)置為fasle 不往eureka-server注冊fetch-registry: true #應(yīng)用是否拉取服務(wù)列表到本地registry-fetch-interval-seconds: 10 #為了緩解服務(wù)列表的臟讀問題,時間越短臟讀越少 性能相應(yīng)的消耗回答instance: #實例的配置instance-id: ${eureka.instance.hostname}:${spring.application.name}:${server.port}hostname: localhost #主機名稱或者服務(wù)ipprefer-ip-address: true #以ip的形式顯示具體的服務(wù)信息lease-renewal-interval-in-seconds: 10 #服務(wù)實例的續(xù)約時間間隔
feign:hystrix:enabled: true  # 開啟熔斷

啟動類

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@EnableCircuitBreaker //開啟斷路器
public class CustomerServiceApplication {public static void main(String[] args) {SpringApplication.run(CustomerServiceApplication.class, args);}}

feign

/*** 這里需要制定熔斷類*/
@FeignClient(value = "rent-car-service",fallback = CustomerRentFeignHystrix.class)
public interface CustomerRentFeign {@GetMapping("rent")String rent();}

hystrix

@Component
public class CustomerRentFeignHystrix implements CustomerRentFeign {/*** 這個方法是備選方案* @return*/@Overridepublic String rent() {return "備選方案";}
}

controller

@RestController
public class CustomerController {@Autowiredprivate CustomerRentFeign customerRentFeign;@GetMapping("customerRent")public String CustomerRent(){System.out.println("客戶來租車了");String rent = customerRentFeign.rent();return rent;}}

服務(wù)啟動

先啟動Eureka服務(wù)端再啟動服務(wù)提供者最后啟動服務(wù)消費者

在這里插入圖片描述
當(dāng)我們將服務(wù)提供者進行下線之后,服務(wù)消費者再調(diào)用服務(wù)提供者的時候,先進行了熔斷,再執(zhí)行了降級處理(執(zhí)行備選方案)。
在這里插入圖片描述

總結(jié)

  1. 以上就是Hystrix的基本使用,當(dāng)服務(wù)出現(xiàn)故障時,開啟熔斷器執(zhí)行降級方案。
  2. 后序博主會手動實現(xiàn)熔斷器來加強對熔斷器的理解。
  3. 由于Netflix已經(jīng)宣布停止維護Hystrix,推薦使用Resilience4j或Sentinel等其他替代方案來處理容錯和熔斷問題。
http://www.risenshineclean.com/news/53968.html

相關(guān)文章:

  • 交河做網(wǎng)站價格windows優(yōu)化大師可靠嗎
  • 如何承接設(shè)計網(wǎng)站建設(shè)傳媒網(wǎng)站
  • 諸城做網(wǎng)站的公司php視頻轉(zhuǎn)碼
  • 在線直播網(wǎng)站怎么做人民網(wǎng)輿情數(shù)據(jù)中心官網(wǎng)
  • 國外大型網(wǎng)站曹操seo博客
  • 酒泉做網(wǎng)站網(wǎng)站目錄結(jié)構(gòu)
  • 門戶網(wǎng)站建設(shè)工作方案在線優(yōu)化seo
  • 深圳市建設(shè)科技促進中心網(wǎng)站網(wǎng)絡(luò)優(yōu)化網(wǎng)站
  • 做網(wǎng)站的例子設(shè)計網(wǎng)站官網(wǎng)
  • 佛山門戶網(wǎng)站建設(shè)廣告優(yōu)化師怎么學(xué)
  • 做日語字幕的網(wǎng)站杭州關(guān)鍵詞排名系統(tǒng)
  • 做vi的網(wǎng)站廣告門
  • 廣告設(shè)計圖片 門頭windows優(yōu)化大師有用嗎
  • 零度業(yè)務(wù)網(wǎng)站seo學(xué)校培訓(xùn)班
  • 自己做網(wǎng)站要買域名嗎谷歌seo網(wǎng)站推廣怎么做
  • 網(wǎng)站用微信登錄 要怎么做東莞網(wǎng)站優(yōu)化關(guān)鍵詞排名
  • 鄭州企業(yè)網(wǎng)站開發(fā)信陽seo推廣
  • 南寧網(wǎng)站設(shè)計推廣在線網(wǎng)頁服務(wù)器
  • 正能量網(wǎng)站推薦免費下載名詞解釋seo
  • 網(wǎng)站做的圖上傳后字變得很模糊win7一鍵優(yōu)化工具
  • 上海成品網(wǎng)站google推廣一年的費用
  • 沈營商環(huán)境建設(shè)監(jiān)督局網(wǎng)站網(wǎng)站開發(fā)的公司
  • 移動網(wǎng)站設(shè)計方案好的競價推廣托管
  • 網(wǎng)站做301好不好百度app下載安裝官方免費版
  • 做網(wǎng)站如何避免侵權(quán)網(wǎng)絡(luò)營銷的重要性
  • 蘇州做網(wǎng)站多少錢廣告投放平臺系統(tǒng)
  • 購買域名需要注意什么seo關(guān)鍵詞選取工具
  • 網(wǎng)站關(guān)于我們怎么做網(wǎng)絡(luò)營銷策劃需要包括哪些內(nèi)容
  • 程序開發(fā)外包平臺公司百度官網(wǎng)優(yōu)化
  • 做全球視頻網(wǎng)站賺錢嗎英文網(wǎng)站推廣