<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          重磅!騰訊正式開源SpringCloud全套解決方案!

          共 7122字,需瀏覽 15分鐘

           ·

          2022-07-16 19:45

          Spring Cloud Tencent 是什么

          Spring Cloud Tencent 是騰訊開源的一站式微服務(wù)解決方案。Spring Cloud Tencent 實(shí)現(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 ,實(shí)現(xiàn)各種分布式微服務(wù)場景。

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

          項(xiàng)目地址:https://github.com/Tencent/spring-cloud-tencent

          一、安裝北極星

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

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

          北極星安裝非常的簡單下載響應(yīng)平臺的 zip 直接運(yùn)行即可,下載地址: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 機(jī)制實(shí)現(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 最新的文件加載機(jī)制

          • 北極星控制臺增加配置
          • 代碼使用配置
          @Value("${name:}")
          private String name;

          四、服務(wù)限流

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

          • 服務(wù)增加 polaris-ratelimit 依賴,使用限流組件時(shí)添加 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

          六、限流熔斷

          故障實(shí)例熔斷是常見的一種容錯(cuò)保護(hù)機(jī)制。故障實(shí)例熔斷能實(shí)現(xiàn)主調(diào)方迅速自動屏蔽錯(cuò)誤率高或故障的服務(wù)實(shí)例,并啟動定時(shí)任務(wù)對熔斷實(shí)例進(jìn)行探活。在達(dá)到恢復(fù)條件后對其進(jìn)行半開恢復(fù)。在半開恢復(fù)后,釋放少量請求去進(jìn)行真實(shí)業(yè)務(wù)探測。并根據(jù)真實(shí)業(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)用實(shí)現(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

          項(xiàng)目源碼地址

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

          程序汪資料鏈接

          程序汪接的7個(gè)私活都在這里,經(jīng)驗(yàn)整理

          Java項(xiàng)目分享  最新整理全集,找項(xiàng)目不累啦 07版

          堪稱神級的Spring Boot手冊,從基礎(chǔ)入門到實(shí)戰(zhàn)進(jìn)階

          臥槽!字節(jié)跳動《算法中文手冊》火了,完整版 PDF 開放下載!

          臥槽!阿里大佬總結(jié)的《圖解Java》火了,完整版PDF開放下載!

          字節(jié)跳動總結(jié)的設(shè)計(jì)模式 PDF 火了,完整版開放下載!


          歡迎添加程序汪個(gè)人微信 itwang009  進(jìn)粉絲群或圍觀朋友圈

          瀏覽 97
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  久久人妻电影 | 亚洲韩日在线 | 91在线无码精品秘 入口九色十 | 四虎成人精品永久免费AV | 国产成人三级在线播放 |