欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringCloud?Tencent?全套解決方案源碼分析

 更新時間:2022年07月04日 10:28:12   作者:葉秋學長  
Spring Cloud Tencent實現(xiàn)Spring Cloud標準微服務SPI,開發(fā)者可以基于Spring Cloud Tencent開發(fā)Spring Cloud微服務架構應用,Spring Cloud Tencent 的核心依托騰訊開源的一站式服務發(fā)現(xiàn)與治理平臺 Polarismesh,實現(xiàn)各種分布式微服務場景,感興趣的朋友一起看看吧

Spring Cloud Tencent 是什么?

Spring Cloud Tencent 是騰訊開源的一站式微服務解決方案。Spring Cloud Tencent 實現(xiàn)了 Spring Cloud 標準微服務 SPI,開發(fā)者可以基于 Spring Cloud Tencent 快速開發(fā) Spring Cloud 微服務架構應用。Spring Cloud Tencent 的核心依托騰訊開源的一站式服務發(fā)現(xiàn)與治理平臺 Polarismesh ,實現(xiàn)各種分布式微服務場景。

Spring Cloud Tencent 提供的能力包括但不限于:

項目地址:https://github.com/Tencent/spring-cloud-tencent

項目源碼地址

https://github.com/lltx/spring-cloud-tencent-demo

一、安裝北極星

北極星是騰訊開源的服務發(fā)現(xiàn)和治理中心,致力于解決分布式或者微服務架構中的服務可見、故障容錯、流量控制和安全問題。雖然,業(yè)界已經有些組件可以解決其中一部分問題,但是缺少一個標準的、多語言的、框架無關的實現(xiàn)。

騰訊具有海量的分布式服務,加上業(yè)務線和技術棧的多樣性,沉淀了大大小小數(shù)十個相關組件。從 2019 年開始,我們通過北極星對這些組件進行抽象和整合,打造公司統(tǒng)一的服務發(fā)現(xiàn)和治理方案,幫助業(yè)務提升研發(fā)效率和運營質量。

北極星安裝非常的簡單下載響應平臺的 zip 直接運行即可,下載地址:https://github.com/polarismesh/polaris/releases/tag/v1.9.0

二、服務注冊與發(fā)現(xiàn)

服務增加 polaris-discovery 依賴

<dependency>
    <groupId>com.tencent.cloud</groupId>
    <artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>

application.yaml 接入 polaris server

spring:
  cloud:
    polaris:
      address: grpc://127.0.0.1:8091

啟動服務觀察 polaris console

服務調用示例

@Bean
@LoadBalanced
public RestTemplate restTemplate() {
  return new RestTemplate();
}
 
@Autowired
private RestTemplate restTemplate;
 
@GetMapping("/consumer")
public String consumer() {
  return restTemplate.getForObject("http://lengleng-tencent-discovery-provider/provider/lengleng", String.class);
}

三、配置管理

在應用啟動 Bootstrap 階段,Spring Cloud 會調用 PolarisConfigFileLocator 從 Polaris 服務端獲取配置文件并加載到 Spring 上下文里。通過 Spring Boot 標準的 @Value,@ConfigurationProperties 注解即可獲取配置內容。動態(tài)配置刷新能力,則通過 Spring Cloud 標準的 @RefreshScope 機制實現(xiàn)。

服務增加 polaris-config 依賴

<dependency>
    <groupId>com.tencent.cloud</groupId>
    <artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
</dependency>

bootstrap.yaml 接入 polaris-config

spring:
  cloud:
    polaris:
      address: grpc://127.0.0.1:8081
      config:
        groups:
          - name: ${spring.application.name}
            files: "application"

特別注意: 這里需要配置在 bootstrap, spring-cloud-tencent 未適配 spring boot 最新的文件加載機制

北極星控制臺增加配置

代碼使用配置

@Value("${name:}")
private String name;

四、服務限流

服務限流是最常見的一種服務自我保護措施之一,防止流量洪峰打垮服務。Spring Cloud Tencent Rate Limit 模塊內置了針對 Spring Web 和 Spring WebFlux 場景的限流 Filter,結合 Polaris 的限流功能幫忙業(yè)務快速接入限流能力。

服務增加 polaris-ratelimit 依賴,使用限流組件時添加 discovery ,方便在服務列表編輯

<dependency>
    <groupId>com.tencent.cloud</groupId>
    <artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>
<dependency>
    <groupId>com.tencent.cloud</groupId>
    <artifactId>spring-cloud-starter-tencent-polaris-ratelimit</artifactId>
</dependency>

服務接入 polaris-ratelimit

spring:
  cloud:
    polaris:
      address: grpc://127.0.0.1:8091
      namespace: default
      ratelimit:
        reject-http-code: 403
        reject-request-tips: "lengleng test rate limit"

北極星控制臺增加限流規(guī)則

五、服務路由

polaris 能夠實現(xiàn)的路由形式較多元數(shù)據(jù)路由、就近路由、規(guī)則路由、自定義路由等形式,本文以元數(shù)據(jù)路由演示,如下圖只會路由至相同元數(shù)據(jù)信息的服務

服務增加 polaris-router 依賴

<dependency>
    <groupId>com.tencent.cloud</groupId>
    <artifactId>spring-cloud-starter-tencent-polaris-router</artifactId>
</dependency>

服務標記元數(shù)據(jù)

spring:
  cloud:
    polaris:
      address: grpc://127.0.0.1:8091
    tencent:
      metadata:
        content:
          version: local

六、限流熔斷

故障實例熔斷是常見的一種容錯保護機制。故障實例熔斷能實現(xiàn)主調方迅速自動屏蔽錯誤率高或故障的服務實例,并啟動定時任務對熔斷實例進行探活。在達到恢復條件后對其進行半開恢復。在半開恢復后,釋放少量請求去進行真實業(yè)務探測。并根據(jù)真實業(yè)務探測結果去判斷是否完全恢復正常。

添加限流熔斷相關的依賴 polaris-circuitbreaker

<dependency>
    <groupId>com.tencent.cloud</groupId>
    <artifactId>spring-cloud-starter-tencent-polaris-circuitbreaker</artifactId>
</dependency>
 
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
 
<dependency>
    <groupId>com.tencent.cloud</groupId>
    <artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>
 
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-circuitbreaker-spring-retry</artifactId>
</dependency>
 
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

提供 Feign 服務調用實現(xiàn)

spring-cloud-tencent 當前版本僅支持 feign 熔斷

@FeignClient(contextId = "demoFeign", value = "lengleng-circuitbreaker-tencent-circuitbreaker-provider",
  fallback = DemoFeignFallback.class)
public interface DemoFeign {
 @GetMapping("/provider")
 String get(@RequestParam String name);
 
}

服務接入 polaris-circuitbreaker

spring:
  cloud:
    polaris:
      address: grpc://127.0.0.1:8091
#開啟斷路器
feign:
  circuitbreaker:
    enabled: true

編寫熔斷規(guī)則 polaris.yml

consumer:
  circuitBreaker:
    checkPeriod: 100ms
    chain:
      - errorCount
      - errorRate
    plugin:
      errorCount:
        continuousErrorThreshold: 1
        metricNumBuckets: 1
      errorRate:
        errorRateThreshold: 100
        metricStatTimeWindow: 1s
        requestVolumeThreshold: 1

到此這篇關于SpringCloud Tencent 全套解決方案的文章就介紹到這了,更多相關SpringCloud Tencent內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Mybatis分頁插件PageHelper手寫實現(xiàn)示例

    Mybatis分頁插件PageHelper手寫實現(xiàn)示例

    這篇文章主要為大家介紹了Mybatis分頁插件PageHelper手寫實現(xiàn)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • 使用Mybatis如何實現(xiàn)多個控制條件查詢

    使用Mybatis如何實現(xiàn)多個控制條件查詢

    這篇文章主要介紹了使用Mybatis如何實現(xiàn)多個控制條件查詢,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Java中SpringSecurity密碼錯誤5次鎖定用戶的實現(xiàn)方法

    Java中SpringSecurity密碼錯誤5次鎖定用戶的實現(xiàn)方法

    這篇文章主要介紹了Java中SpringSecurity密碼錯誤5次鎖定用戶的實現(xiàn)方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-03-03
  • Quartz作業(yè)調度基本使用詳解

    Quartz作業(yè)調度基本使用詳解

    這篇文章主要為大家介紹了Quartz作業(yè)調度基本使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-08-08
  • Flowable執(zhí)行完畢的流程查找方法

    Flowable執(zhí)行完畢的流程查找方法

    這篇文章主要為大家介紹了Flowable執(zhí)行完畢的流程查找方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • 基于springboot 長輪詢的實現(xiàn)操作

    基于springboot 長輪詢的實現(xiàn)操作

    這篇文章主要介紹了基于springboot 長輪詢的實現(xiàn)操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-01-01
  • Java一個簡單的紅包生成算法

    Java一個簡單的紅包生成算法

    今天小編就為大家分享一篇關于Java一個簡單的紅包生成算法,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01
  • Spring事件監(jiān)聽機制ApplicationEvent方式

    Spring事件監(jiān)聽機制ApplicationEvent方式

    這篇文章主要介紹了Spring事件監(jiān)聽機制ApplicationEvent方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Java interrupt()方法使用實例介紹

    Java interrupt()方法使用實例介紹

    一個線程在未正常結束之前, 被強制終止是很危險的事情. 因為它可能帶來完全預料不到的嚴重后果比如會帶著自己所持有的鎖而永遠的休眠,遲遲不歸還鎖等。 所以你看到Thread.suspend, Thread.stop等方法都被Deprecated了
    2023-02-02
  • JAVA中字符串如何與整型數(shù)字相加

    JAVA中字符串如何與整型數(shù)字相加

    這篇文章主要介紹了JAVA中字符串如何與整型數(shù)字相加,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-07-07

最新評論