亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

Spring Cloud Tencent 是什么?

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

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

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

項目源碼地址

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

一、安裝北極星

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

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

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

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

服務(wù)增加 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

啟動服務(wù)觀察 polaris console

服務(wù)調(diào)用示例

@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);
}

三、配置管理

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

服務(wù)增加 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;

四、服務(wù)限流

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

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

<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>

服務(wù)接入 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ī)則

五、服務(wù)路由

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

服務(wù)增加 polaris-router 依賴

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

服務(wù)標(biāo)記元數(shù)據(jù)

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

六、限流熔斷

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

添加限流熔斷相關(guān)的依賴 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 服務(wù)調(diào)用實現(xiàn)

spring-cloud-tencent 當(dāng)前版本僅支持 feign 熔斷

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

服務(wù)接入 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

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

相關(guān)文章

  • 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è)調(diào)度基本使用詳解

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

    這篇文章主要為大家介紹了Quartz作業(yè)調(diào)度基本使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    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一個簡單的紅包生成算法

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

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

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

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

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

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

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

最新評論