国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - Java教程 - spring cloud Hystrix斷路器的使用(熔斷器)

spring cloud Hystrix斷路器的使用(熔斷器)

2021-05-26 12:53TS笑天 Java教程

這篇文章主要介紹了spring cloud Hystrix斷路器的使用(熔斷器),小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

1.hystrix客戶端

netflix已經創建了一個名為hystrix的庫,實現了斷路器的模式。在microservice架構通常有多個層的服務調用。

spring cloud Hystrix斷路器的使用(熔斷器)

低水平的服務的服務失敗會導致級聯故障一直給到用戶。當調用一個特定的服務達到一定閾值(默認5秒失敗20次),打開斷路器。在錯誤的情況下和一個開啟的斷路回滾應可以由開發人員提供。

spring cloud Hystrix斷路器的使用(熔斷器)

有一個斷路器阻止級聯失敗并且允許關閉服務一段時間進行愈合。回滾會被其他hystrix保護調用,靜態數據或健全的空值。
代碼如下:

?
1
2
3
4
5
6
7
8
9
@springbootapplication
@enablecircuitbreaker
public class application {
 
  public static void main(string[] args) {
    new springapplicationbuilder(application.class).web(true).run(args);
  }
 
}
?
1
2
3
4
5
6
7
8
9
10
11
12
@component
public class storeintegration {
 
  @hystrixcommand(fallbackmethod = "defaultstores")
  public object getstores(map<string, object> parameters) {
    //do stuff that might fail
  }
 
  public object defaultstores(map<string, object> parameters) {
    return /* something useful */;
  }
}

@hystrixcommand是由netflix contrib 庫提供,叫做javanica。spring cloud自動包裝spring bean與注釋的代理連接到hystrix斷路器。斷路器計算何時打開和關閉斷路,并在失敗的情況下做什么。

配置@hystrixcommand可以使用commandproperties屬性的列表@hystrixproperty注釋。詳細請看https://github.com/netflix/hystrix/tree/master/hystrix-contrib/hystrix-javanica#configuration
https://github.com/netflix/hystrix/wiki/configuration

1.1 傳播安全上下文或者使用spring范圍

如果你想要一些線程本地上下文傳播到@hystrixcommand默認聲明將不會工作,因為它執行線程池中的命令(在超時的情況下)。

可以切換hystrix使用一些配置用相同的線程調用者,或直接在注釋,讓它使用不同的“隔離策略”(isolation strategy)。

例如:

?
1
2
3
4
5
6
@hystrixcommand(fallbackmethod = "stubmyservice",
  commandproperties = {
   @hystrixproperty(name="execution.isolation.strategy", value="semaphore")
  }
)
...

詳細內容請參考https://github.com/netflix/hystrix/wiki/configuration

1.2 健康監控

連接的斷路器的狀態也暴露在調用應用程序的/health端點。

?
1
2
3
4
5
6
7
8
9
{
  "hystrix": {
    "opencircuitbreakers": [
      "storeintegration::getstoresbylocationlink"
    ],
    "status": "circuit_open"
  },
  "status": "up"
}

1.3 hystrix metrics stream(hystrix指標流)

spring-boot-starter-actuator中實現了hystrix metrics stream。暴露/hystrix.stream作為一個管理端點。

?
1
2
3
4
<dependency>
    <groupid>org.springframework.boot</groupid>
    <artifactid>spring-boot-starter-actuator</artifactid>
  </dependency>

2.hystrix dashboard

hystrix的主要好處之一是它收集關于每個hystrixcommand組指標。hystrix儀表板顯示每個斷路器的健康高效的方式。

spring cloud Hystrix斷路器的使用(熔斷器)

運行hystrix儀表板需要在spring boot主類上標注@enablehystrixdashboard。然后訪問/ hystrix查看儀表盤,在hystrix客戶端應用使用/hystrix.stream監控。

2.1 turbine

看一個實例hystrix數據對于整個系統的健康不是很有用。turbine是一個應用程序,該應用程序匯集了所有相關的/hystrix.stream端點到 /turbine.stream用于hystrix儀表板。運行turbine使用@enableturbine注釋你的主類,使用spring-cloud-starter-turbine這個jar。配置請參考https://github.com/netflix/turbine/wiki/configuration-(1.x)

唯一的區別是turbine.instanceurlsuffix不需要端口號前綴,因為這是自動處理,除非turbine.instanceinsertport = false。

turbine.appconfig配置是一個eureka服務id列表,turbine將使用這個配置查詢實例。turbine stream在hystrix dashboard中使用如下的url配置:

http://my.turbine.server:8080/turbine.stream?cluster=,如果集群的名稱是default,集群參數可以忽略)。這個集群參數必須和turbine.aggregator.clusterconfig匹配。從eureka返回的值都是大寫的,因此我們希望下面的例子可以工作,如果一個app使用eureka注冊,并且被叫做customers:

?
1
2
3
4
turbine:
 aggregator:
  clusterconfig: customers
 appconfig: customers

clustername可以使用spel表達式定義,在turbine.clusternameexpression。

默認值是appname,意思是eureka服務id最終將作為集群的key,例如customers的instanceinfo有一個customers的appname。另外一個例子是turbine.clusternameexpression=asgname,將從aws asg name獲取集群名稱。

另一個例子:

?
1
2
3
4
5
turbine:
 aggregator:
  clusterconfig: system,user
 appconfig: customers,stores,ui,admin
 clusternameexpression: metadata['cluster']

在這種情況下,集群名稱從4個服務從其元數據映射,期望包含“system”和“user”。

所有的app使用default,你需要一個文字表達式(使用單引號):

?
1
2
3
turbine:
 appconfig: customers,stores
 clusternameexpression: 'default'

spring cloud提供一個spring-cloud-starter-turbine,所有依賴項你需要運行一個turbine服務器。使用@enableturbine創建一個spring boot應用。

2.2 turbine amqp

在某些環境中(如在paas),典型的turbine模型的指標從所有分布式hystrix命令不起作用。在這種情況下,你可能想要你hystrix命令推動指標turbine,和spring cloud,就要使用amqp消息傳遞。所有您需要做的是在客戶端添加一個依賴spring-cloud-netflix-hystrix-amqp并確保代rabbitmq可用。(有關詳細信息,請參閱彈簧引導文檔如何配置客戶端憑據,但它應該工作的當地代理或云計算)。

hystrix相關的其他文章:

hystrix緩存功能的使用:http://www.jfrwli.cn/article/166243.html

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://blog.csdn.net/zhuchuangang/article/details/51289593

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 免费污网址 | 操久久 | www.99re | 成人男女啪啪免费观软件 | 中文字幕91| 日日夜夜摸 | 久久影音 | 欧美亚洲日本 | 欧美福利 | 色综合天天天天做夜夜夜夜做 | 99999色| 综合久久久 | 亚洲午夜视频在线观看 | 国产美女视频自拍 | 久久精品这里热有精品 | 亚洲欧美综合乱码精品成人网 | 中文字幕一区二区在线观看 | 欧美一区二区三区啪啪 | 黄片毛片毛片毛片 | 久久久国产视频 | 国产欧美精品区一区二区三区 | 久久av一区二区 | 极品一区 | 欧美视频第一页 | 欧美大片一区二区 | 涩涩涩久久久成人精品 | 精品国产乱码久久久久久密桃99 | 黄色小视频免费 | 韩国成人精品a∨在线观看 欧美精品综合 | 黄色成人在线 | 国产一区二区精品丝袜 | 91精品国产欧美一区二区成人 | 高清久久 | 成人在线小视频 | 国产成人精品一区二区三区四区 | 性刺激久久久久久久久九色 | 午夜免费av | 国产特级毛片aaaaaa毛片 | 尤物在线观看网站 | 青青草欧美 | 精品国产乱码久久久久久1区2区 |