├── .springjavaformatconfig ├── .editorconfig ├── tencent-discovery ├── tencent-discovery-provider │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── tencentdiscoveryprovider │ │ │ │ ├── TencentDiscoveryProviderApplication.java │ │ │ │ └── controller │ │ │ │ └── ProviderController.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentdiscoveryprovider │ │ │ └── TencentDiscoveryProviderApplicationTests.java │ └── pom.xml ├── tencent-discovery-consumer │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yaml │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentdiscovery │ │ │ └── consumer │ │ │ ├── TencentDiscoveryConsumerApplication.java │ │ │ ├── config │ │ │ └── DemoConfiguration.java │ │ │ └── controller │ │ │ └── ConsumerController.java │ └── pom.xml └── pom.xml ├── tencent-circuitbreaker ├── tencent-circuitbreaker-provider │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── tencentdiscoveryprovider │ │ │ │ ├── controller │ │ │ │ └── ProviderController.java │ │ │ │ └── TencentCircuitbreakerProviderApplication.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentdiscoveryprovider │ │ │ └── TencentDiscoveryProviderApplicationTests.java │ └── pom.xml ├── tencent-circuitbreaker-provider-error │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── tencentdiscoveryprovider │ │ │ │ ├── controller │ │ │ │ └── ProviderController.java │ │ │ │ └── TencentCircuitbreakerProviderApplication.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentdiscoveryprovider │ │ │ └── TencentDiscoveryProviderApplicationTests.java │ └── pom.xml ├── tencent-circuitbreaker-consumer │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yaml │ │ │ └── polaris.yml │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentdiscovery │ │ │ └── consumer │ │ │ ├── feign │ │ │ ├── DemoFeignFallback.java │ │ │ └── DemoFeign.java │ │ │ ├── TencentCircuitbreakerConsumerApplication.java │ │ │ └── controller │ │ │ └── ConsumerController.java │ └── pom.xml └── pom.xml ├── tencent-router ├── tencent-router-provider │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── tencentdiscoveryprovider │ │ │ │ ├── controller │ │ │ │ └── ProviderController.java │ │ │ │ └── TencentRouterProviderApplication.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentdiscoveryprovider │ │ │ └── TencentDiscoveryProviderApplicationTests.java │ └── pom.xml ├── tencent-router-consumer │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yaml │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentdiscovery │ │ │ └── consumer │ │ │ ├── TencentRouterConsumerApplication.java │ │ │ ├── feign │ │ │ └── DemoFeign.java │ │ │ └── controller │ │ │ └── ConsumerController.java │ └── pom.xml ├── tencent-router-provider2 │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yaml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── tencentdiscoveryprovider │ │ │ │ ├── controller │ │ │ │ └── ProviderController.java │ │ │ │ └── TencentRouter2ProviderApplication.java │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentdiscoveryprovider │ │ │ └── TencentDiscoveryProviderApplicationTests.java │ └── pom.xml └── pom.xml ├── tencent-rate-limit ├── src │ └── main │ │ ├── resources │ │ └── bootstrap.yml │ │ └── java │ │ └── com │ │ └── example │ │ └── rate │ │ └── limit │ │ ├── TencentRateLimitApplication.java │ │ └── controller │ │ └── RateLimitController.java └── pom.xml ├── tencent-config ├── src │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── tencentconfig │ │ │ └── TencentConfigApplicationTests.java │ └── main │ │ ├── resources │ │ └── bootstrap.yml │ │ └── java │ │ └── com │ │ └── example │ │ └── tencentconfig │ │ ├── TencentConfigApplication.java │ │ └── controller │ │ └── ConfigController.java └── pom.xml ├── .gitignore ├── pom.xml └── README.md /.springjavaformatconfig: -------------------------------------------------------------------------------- 1 | java-baseline=8 2 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*.{groovy,java,kt,xml}] 4 | indent_style = tab 5 | indent_size = 4 6 | continuation_indent_size = 8 7 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-provider/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: lengleng-@artifactId@ 4 | cloud: 5 | polaris: 6 | address: grpc://183.47.111.80:8091 7 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: lengleng-circuitbreaker-@artifactId@ 4 | cloud: 5 | polaris: 6 | address: grpc://183.47.111.80:8091 7 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-consumer/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8089 3 | spring: 4 | application: 5 | name: lengleng-@artifactId@ 6 | cloud: 7 | polaris: 8 | address: grpc://183.47.111.80:8091 9 | 10 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider-error/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: lengleng-circuitbreaker-tencent-circuitbreaker-provider 4 | cloud: 5 | polaris: 6 | address: grpc://183.47.111.80:8091 7 | server: 8 | port: 8012 9 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: lengleng-circuitbreaker-@artifactId@ 4 | cloud: 5 | polaris: 6 | address: grpc://183.47.111.80:8091 7 | tencent: 8 | metadata: 9 | content: 10 | version: dev 11 | -------------------------------------------------------------------------------- /tencent-rate-limit/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: lengleng_tencent-rate-limit 4 | cloud: 5 | polaris: 6 | address: grpc://183.47.111.80:8091 7 | namespace: default 8 | ratelimit: 9 | reject-http-code: 403 10 | reject-request-tips: "hellO rate limit" 11 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-consumer/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8089 3 | spring: 4 | application: 5 | name: lengleng-router-@artifactId@ 6 | cloud: 7 | polaris: 8 | address: grpc://183.47.111.80:8091 9 | tencent: 10 | metadata: 11 | content: 12 | version: local 13 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-consumer/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8089 3 | spring: 4 | application: 5 | name: lengleng-circuitbreaker-@artifactId@ 6 | cloud: 7 | polaris: 8 | address: grpc://183.47.111.80:8091 9 | 10 | #开启断路器 11 | feign: 12 | circuitbreaker: 13 | enabled: true 14 | -------------------------------------------------------------------------------- /tencent-config/src/test/java/com/example/tencentconfig/TencentConfigApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentconfig; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TencentConfigApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider2/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: lengleng-circuitbreaker-tencent-circuitbreaker-provider 4 | cloud: 5 | polaris: 6 | address: grpc://183.47.111.80:8091 7 | tencent: 8 | metadata: 9 | content: 10 | version: local 11 | server: 12 | port: 8012 13 | -------------------------------------------------------------------------------- /tencent-config/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: lengleng_tencent-config 4 | cloud: 5 | polaris: 6 | address: grpc://183.47.111.80:8091 7 | namespace: default 8 | config: 9 | auto-refresh: true # auto refresh when config file changed 10 | groups: 11 | - name: ${spring.application.name} # group name 12 | files: "application" 13 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider/src/test/java/com/example/tencentdiscoveryprovider/TencentDiscoveryProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TencentDiscoveryProviderApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider2/src/test/java/com/example/tencentdiscoveryprovider/TencentDiscoveryProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TencentDiscoveryProviderApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-provider/src/test/java/com/example/tencentdiscoveryprovider/TencentDiscoveryProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TencentDiscoveryProviderApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider/src/test/java/com/example/tencentdiscoveryprovider/TencentDiscoveryProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TencentDiscoveryProviderApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-consumer/src/main/resources/polaris.yml: -------------------------------------------------------------------------------- 1 | consumer: 2 | circuitBreaker: 3 | checkPeriod: 100ms 4 | chain: 5 | - errorCount 6 | - errorRate 7 | plugin: 8 | errorCount: 9 | continuousErrorThreshold: 1 10 | metricNumBuckets: 1 11 | errorRate: 12 | errorRateThreshold: 100 13 | metricStatTimeWindow: 1s 14 | requestVolumeThreshold: 1 15 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider-error/src/test/java/com/example/tencentdiscoveryprovider/TencentDiscoveryProviderApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class TencentDiscoveryProviderApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-config/src/main/java/com/example/tencentconfig/TencentConfigApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentconfig; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TencentConfigApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TencentConfigApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-rate-limit/src/main/java/com/example/rate/limit/TencentRateLimitApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.rate.limit; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TencentRateLimitApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TencentRateLimitApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-consumer/src/main/java/com/example/tencentdiscovery/consumer/feign/DemoFeignFallback.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer.feign; 2 | 3 | import org.springframework.stereotype.Service; 4 | 5 | /** 6 | * @author lengleng 7 | * @date 2022/6/21 8 | */ 9 | @Service 10 | public class DemoFeignFallback implements DemoFeign { 11 | 12 | @Override 13 | public String get(String name) { 14 | return null; 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider/src/main/java/com/example/tencentdiscoveryprovider/controller/ProviderController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider.controller; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author lengleng 7 | * @date 2022/6/20 8 | */ 9 | @RestController 10 | @RequestMapping 11 | public class ProviderController { 12 | 13 | @GetMapping("/provider") 14 | public String provider(@RequestParam String name) { 15 | return "dev"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider2/src/main/java/com/example/tencentdiscoveryprovider/controller/ProviderController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider.controller; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author lengleng 7 | * @date 2022/6/20 8 | */ 9 | @RestController 10 | @RequestMapping 11 | public class ProviderController { 12 | 13 | @GetMapping("/provider") 14 | public String provider(@RequestParam String name) { 15 | return "local"; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider/src/main/java/com/example/tencentdiscoveryprovider/TencentRouterProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TencentRouterProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TencentRouterProviderApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider/src/main/java/com/example/tencentdiscoveryprovider/controller/ProviderController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider.controller; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author lengleng 7 | * @date 2022/6/20 8 | */ 9 | @RestController 10 | @RequestMapping 11 | public class ProviderController { 12 | 13 | @GetMapping("/provider") 14 | public String provider(@RequestParam String name) { 15 | return name; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider2/src/main/java/com/example/tencentdiscoveryprovider/TencentRouter2ProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TencentRouter2ProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TencentRouter2ProviderApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-provider/src/main/java/com/example/tencentdiscoveryprovider/TencentDiscoveryProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TencentDiscoveryProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TencentDiscoveryProviderApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-consumer/src/main/java/com/example/tencentdiscovery/consumer/TencentDiscoveryConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TencentDiscoveryConsumerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TencentDiscoveryConsumerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider-error/src/main/java/com/example/tencentdiscoveryprovider/controller/ProviderController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider.controller; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | /** 6 | * @author lengleng 7 | * @date 2022/6/20 8 | */ 9 | @RestController 10 | @RequestMapping 11 | public class ProviderController { 12 | 13 | @GetMapping("/provider") 14 | public String provider(@RequestParam String name) { 15 | int i = 1 / 0; 16 | return name; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider/src/main/java/com/example/tencentdiscoveryprovider/TencentCircuitbreakerProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TencentCircuitbreakerProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TencentCircuitbreakerProviderApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider-error/src/main/java/com/example/tencentdiscoveryprovider/TencentCircuitbreakerProviderApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TencentCircuitbreakerProviderApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TencentCircuitbreakerProviderApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /tencent-rate-limit/src/main/java/com/example/rate/limit/controller/RateLimitController.java: -------------------------------------------------------------------------------- 1 | package com.example.rate.limit.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @author lengleng 9 | * @date 2022/6/21 10 | */ 11 | @RestController 12 | @RequestMapping 13 | public class RateLimitController { 14 | 15 | @GetMapping("/rate-limit") 16 | public String rateLimit() { 17 | return "success"; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-consumer/src/main/java/com/example/tencentdiscovery/consumer/TencentRouterConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @EnableFeignClients 8 | @SpringBootApplication 9 | public class TencentRouterConsumerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(TencentRouterConsumerApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-consumer/src/main/java/com/example/tencentdiscovery/consumer/feign/DemoFeign.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | 7 | /** 8 | * @author lengleng 9 | * @date 2022/6/21 10 | */ 11 | @FeignClient(contextId = "demoFeign", value = "lengleng-circuitbreaker-tencent-circuitbreaker-provider") 12 | public interface DemoFeign { 13 | 14 | @GetMapping("/provider") 15 | String get(@RequestParam String name); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-consumer/src/main/java/com/example/tencentdiscovery/consumer/TencentCircuitbreakerConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @EnableFeignClients 8 | @SpringBootApplication 9 | public class TencentCircuitbreakerConsumerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(TencentCircuitbreakerConsumerApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-consumer/src/main/java/com/example/tencentdiscovery/consumer/feign/DemoFeign.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | 7 | /** 8 | * @author lengleng 9 | * @date 2022/6/21 10 | */ 11 | @FeignClient(contextId = "demoFeign", value = "lengleng-circuitbreaker-tencent-circuitbreaker-provider", 12 | fallback = DemoFeignFallback.class) 13 | public interface DemoFeign { 14 | 15 | @GetMapping("/provider") 16 | String get(@RequestParam String name); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-consumer/src/main/java/com/example/tencentdiscovery/consumer/config/DemoConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer.config; 2 | 3 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.client.RestTemplate; 7 | 8 | /** 9 | * @author lengleng 10 | * @date 2022/6/20 11 | */ 12 | @Configuration(proxyBeanMethods = false) 13 | public class DemoConfiguration { 14 | 15 | @Bean 16 | @LoadBalanced 17 | public RestTemplate restTemplate() { 18 | return new RestTemplate(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-provider/src/main/java/com/example/tencentdiscoveryprovider/controller/ProviderController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscoveryprovider.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author lengleng 10 | * @date 2022/6/20 11 | */ 12 | @RestController 13 | @RequestMapping 14 | public class ProviderController { 15 | 16 | @GetMapping("/provider/{name}") 17 | public String provider(@PathVariable String name) { 18 | return name; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /tencent-config/src/main/java/com/example/tencentconfig/controller/ConfigController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentconfig.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * 动态配置文件 11 | * 12 | * @author lengleng 13 | * @date 2022/6/20 14 | */ 15 | @RefreshScope 16 | @RestController 17 | @RequestMapping 18 | public class ConfigController { 19 | 20 | @Value("${name:}") 21 | private String name; 22 | 23 | @GetMapping 24 | public String get() { 25 | return name; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tencent-discovery/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | spring-cloud-tencent-demo 7 | org.example 8 | 1.0-SNAPSHOT 9 | 10 | 11 | pom 12 | 4.0.0 13 | tencent-discovery 14 | tencent-discovery 15 | 16 | 17 | tencent-discovery-consumer 18 | tencent-discovery-provider 19 | 20 | 21 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-consumer/src/main/java/com/example/tencentdiscovery/consumer/controller/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer.controller; 2 | 3 | import com.example.tencentdiscovery.consumer.feign.DemoFeign; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author lengleng 11 | * @date 2022/6/20 12 | */ 13 | @RestController 14 | @RequestMapping 15 | public class ConsumerController { 16 | 17 | @Autowired 18 | private DemoFeign demoFeign; 19 | 20 | @GetMapping("/consumer") 21 | public String consumer() { 22 | return demoFeign.get("lengleng"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### gradle ### 2 | .gradle 3 | /build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | 6 | ### STS ### 7 | .settings/ 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | bin/ 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | rebel.xml 22 | 23 | ### NetBeans ### 24 | nbproject/private/ 25 | build/ 26 | nbbuild/ 27 | nbdist/ 28 | .nb-gradle/ 29 | 30 | ### maven ### 31 | target/ 32 | *.war 33 | *.ear 34 | *.zip 35 | *.tar 36 | *.tar.gz 37 | *.versionsBackup 38 | 39 | ### vscode ### 40 | .vscode 41 | 42 | ### logs ### 43 | /logs/ 44 | *.log 45 | polaris/ 46 | 47 | ### temp ignore ### 48 | *.cache 49 | *.diff 50 | *.patch 51 | *.tmp 52 | *.java~ 53 | *.properties~ 54 | *.xml~ 55 | 56 | ### system ignore ### 57 | .DS_Store 58 | Thumbs.db 59 | Servers 60 | .metadata 61 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-consumer/src/main/java/com/example/tencentdiscovery/consumer/controller/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer.controller; 2 | 3 | import com.example.tencentdiscovery.consumer.feign.DemoFeign; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author lengleng 11 | * @date 2022/6/20 12 | */ 13 | @RestController 14 | @RequestMapping 15 | public class ConsumerController { 16 | 17 | @Autowired 18 | private DemoFeign demoFeign; 19 | 20 | @GetMapping("/consumer") 21 | public String consumer() { 22 | return demoFeign.get("lengleng"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tencent-router/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | spring-cloud-tencent-demo 7 | org.example 8 | 1.0-SNAPSHOT 9 | 10 | pom 11 | 4.0.0 12 | 13 | tencent-router 14 | 15 | tencent-router 16 | 17 | 18 | tencent-router-consumer 19 | tencent-router-provider 20 | tencent-router-provider2 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | spring-cloud-tencent-demo 7 | org.example 8 | 1.0-SNAPSHOT 9 | 10 | 11 | pom 12 | 4.0.0 13 | tencent-circuitbreaker 14 | tencent-circuitbreaker 15 | 16 | 17 | tencent-circuitbreaker-consumer 18 | tencent-circuitbreaker-provider 19 | tencent-circuitbreaker-provider-error 20 | 21 | 22 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-consumer/src/main/java/com/example/tencentdiscovery/consumer/controller/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.example.tencentdiscovery.consumer.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | /** 10 | * @author lengleng 11 | * @date 2022/6/20 12 | */ 13 | @RestController 14 | @RequestMapping 15 | public class ConsumerController { 16 | 17 | @Autowired 18 | private RestTemplate restTemplate; 19 | 20 | @GetMapping("/consumer") 21 | public String consumer() { 22 | return restTemplate.getForObject("http://lengleng-tencent-discovery-provider/provider/lengleng", String.class); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.example 8 | spring-cloud-tencent-demo 9 | 1.0-SNAPSHOT 10 | pom 11 | 12 | 13 | 17 14 | 17 15 | 0.0.32 16 | 17 | 18 | 19 | 20 | org.projectlombok 21 | lombok 22 | 1.18.24 23 | provided 24 | 25 | 26 | 27 | 28 | tencent-config 29 | tencent-discovery 30 | tencent-rate-limit 31 | tencent-circuitbreaker 32 | tencent-router 33 | 34 | 35 | 36 | 37 | 38 | io.spring.javaformat 39 | spring-javaformat-maven-plugin 40 | ${spring.checkstyle.plugin} 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /tencent-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-config 13 | 0.0.1-SNAPSHOT 14 | tencent-config 15 | tencent-config 16 | 17 | 17 18 | 19 | 20 | 21 | com.tencent.cloud 22 | spring-cloud-starter-tencent-polaris-config 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-test 33 | test 34 | 35 | 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-maven-plugin 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | com.tencent.cloud 50 | spring-cloud-tencent-dependencies 51 | 1.5.2-2021.0.2 52 | pom 53 | import 54 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-router-provider 13 | 0.0.1-SNAPSHOT 14 | tencent-router-provider 15 | tencent-router-provider 16 | 17 | 17 18 | 19 | 20 | 21 | 22 | com.tencent.cloud 23 | spring-cloud-starter-tencent-polaris-discovery 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | com.tencent.cloud 51 | spring-cloud-tencent-dependencies 52 | 1.5.2-2021.0.2 53 | pom 54 | import 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-provider2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-router-provider2 13 | 0.0.1-SNAPSHOT 14 | tencent-router-provider2 15 | tencent-router-provider2 16 | 17 | 17 18 | 19 | 20 | 21 | 22 | com.tencent.cloud 23 | spring-cloud-starter-tencent-polaris-discovery 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | com.tencent.cloud 51 | spring-cloud-tencent-dependencies 52 | 1.5.2-2021.0.2 53 | pom 54 | import 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-discovery-consumer 13 | 0.0.1-SNAPSHOT 14 | tencent-discovery-consumer 15 | tencent-discovery-consumer 16 | 17 | 17 18 | 19 | 20 | 21 | 22 | com.tencent.cloud 23 | spring-cloud-starter-tencent-polaris-discovery 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | com.tencent.cloud 51 | spring-cloud-tencent-dependencies 52 | 1.5.2-2021.0.2 53 | pom 54 | import 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /tencent-discovery/tencent-discovery-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-discovery-provider 13 | 0.0.1-SNAPSHOT 14 | tencent-discovery-provider 15 | tencent-discovery-provider 16 | 17 | 17 18 | 19 | 20 | 21 | 22 | com.tencent.cloud 23 | spring-cloud-starter-tencent-polaris-discovery 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | com.tencent.cloud 51 | spring-cloud-tencent-dependencies 52 | 1.5.2-2021.0.2 53 | pom 54 | import 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-circuitbreaker-provider 13 | 0.0.1-SNAPSHOT 14 | tencent-circuitbreaker-provider 15 | tencent-circuitbreaker-provider 16 | 17 | 17 18 | 19 | 20 | 21 | 22 | com.tencent.cloud 23 | spring-cloud-starter-tencent-polaris-discovery 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | com.tencent.cloud 51 | spring-cloud-tencent-dependencies 52 | 1.5.2-2021.0.2 53 | pom 54 | import 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-provider-error/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-circuitbreaker-provider-error 13 | 0.0.1-SNAPSHOT 14 | tencent-circuitbreaker-provider-error 15 | tencent-circuitbreaker-provider-error 16 | 17 | 17 18 | 19 | 20 | 21 | 22 | com.tencent.cloud 23 | spring-cloud-starter-tencent-polaris-discovery 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-test 34 | test 35 | 36 | 37 | 38 | 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-maven-plugin 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | com.tencent.cloud 51 | spring-cloud-tencent-dependencies 52 | 1.5.2-2021.0.2 53 | pom 54 | import 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /tencent-rate-limit/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-rate-limit 13 | 0.0.1-SNAPSHOT 14 | tencent-rate-limit 15 | tencent-rate-limit 16 | 17 | 17 18 | 19 | 20 | 21 | com.tencent.cloud 22 | spring-cloud-starter-tencent-polaris-discovery 23 | 24 | 25 | com.tencent.cloud 26 | spring-cloud-starter-tencent-polaris-ratelimit 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-maven-plugin 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | com.tencent.cloud 54 | spring-cloud-tencent-dependencies 55 | 1.5.2-2021.0.2 56 | pom 57 | import 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /tencent-router/tencent-router-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-router-consumer 13 | 0.0.1-SNAPSHOT 14 | tencent-router-consumer 15 | tencent-router-consumer 16 | 17 | 17 18 | 19 | 20 | 21 | 22 | com.tencent.cloud 23 | spring-cloud-starter-tencent-polaris-discovery 24 | 25 | 26 | 27 | com.tencent.cloud 28 | spring-cloud-starter-tencent-polaris-router 29 | 30 | 31 | 32 | org.springframework.cloud 33 | spring-cloud-starter-openfeign 34 | 3.1.2 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-web 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | 49 | 50 | 51 | 52 | org.springframework.boot 53 | spring-boot-maven-plugin 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | com.tencent.cloud 62 | spring-cloud-tencent-dependencies 63 | 1.5.2-2021.0.2 64 | pom 65 | import 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /tencent-circuitbreaker/tencent-circuitbreaker-consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.7.0 9 | 10 | 11 | com.example 12 | tencent-circuitbreaker-consumer 13 | 0.0.1-SNAPSHOT 14 | tencent-circuitbreaker-consumer 15 | tencent-circuitbreaker-consumer 16 | 17 | 17 18 | 2021.0.3 19 | 1.5.2-2021.0.2 20 | 21 | 22 | 23 | 24 | com.tencent.cloud 25 | spring-cloud-starter-tencent-polaris-discovery 26 | 27 | 28 | 29 | com.tencent.cloud 30 | spring-cloud-starter-tencent-polaris-circuitbreaker 31 | 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-loadbalancer 36 | 37 | 38 | 39 | org.springframework.cloud 40 | spring-cloud-circuitbreaker-spring-retry 41 | 42 | 43 | 44 | org.springframework.cloud 45 | spring-cloud-starter-openfeign 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-web 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-test 56 | test 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-maven-plugin 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.cloud 73 | spring-cloud-dependencies 74 | ${spring-cloud.version} 75 | pom 76 | import 77 | 78 | 79 | com.tencent.cloud 80 | spring-cloud-tencent-dependencies 81 | ${spring-cloud-tencent.version} 82 | pom 83 | import 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Spring Cloud Tencent 是什么 2 | 3 | Spring Cloud Tencent 是腾讯开源的一站式微服务解决方案。Spring Cloud Tencent 实现了 Spring Cloud 标准微服务 SPI,开发者可以基于 Spring Cloud Tencent 快速开发 Spring Cloud 微服务架构应用。Spring Cloud Tencent 的核心依托腾讯开源的一站式服务发现与治理平台 Polarismesh ,实现各种分布式微服务场景。 4 | 5 | Spring Cloud Tencent 提供的能力包括但不限于: 6 | 7 | ![架构图](https://minio.pigx.vip/oss/1655809074.jpg) 8 | 9 | ## 一、安装北极星 10 | 11 | 北极星是腾讯开源的服务发现和治理中心,致力于解决分布式或者微服务架构中的服务可见、故障容错、流量控制和安全问题。虽然,业界已经有些组件可以解决其中一部分问题,但是缺少一个标准的、多语言的、框架无关的实现。 12 | 13 | 腾讯具有海量的分布式服务,加上业务线和技术栈的多样性,沉淀了大大小小数十个相关组件。从 2019 年开始,我们通过北极星对这些组件进行抽象和整合,打造公司统一的服务发现和治理方案,帮助业务提升研发效率和运营质量。 14 | 15 | > > [北极星安装非常的简单下载响应平台的 zip 直接运行即可](https://github.com/polarismesh/polaris/releases/tag/v1.9.0 "北极星下载") 16 | 17 | ![北极星界面展示](https://minio.pigx.vip/oss/1655809558.png) 18 | 19 | ## 二、服务注册与发现 20 | 21 | - 服务增加 polaris-discovery 依赖 22 | 23 | ```xml 24 | 25 | com.tencent.cloud 26 | spring-cloud-starter-tencent-polaris-discovery 27 | 28 | ``` 29 | 30 | - application.yaml 接入 polaris server 31 | 32 | ```yaml 33 | spring: 34 | cloud: 35 | polaris: 36 | address: grpc://127.0.0.1:8091 37 | ``` 38 | 39 | - 启动服务观察 polaris console 40 | 41 | ![](https://minio.pigx.vip/oss/1655809927.png) 42 | 43 | - 服务调用示例 44 | 45 | ```java 46 | @Bean 47 | @LoadBalanced 48 | public RestTemplate restTemplate() { 49 | return new RestTemplate(); 50 | } 51 | 52 | @Autowired 53 | private RestTemplate restTemplate; 54 | 55 | @GetMapping("/consumer") 56 | public String consumer() { 57 | return restTemplate.getForObject("http://lengleng-tencent-discovery-provider/provider/lengleng", String.class); 58 | } 59 | ``` 60 | 61 | ## 三、 配置管理 62 | 63 | > > 在应用启动 Bootstrap 阶段,Spring Cloud 会调用 PolarisConfigFileLocator 从 Polaris 服务端获取配置文件并加载到 Spring 上下文里。通过 Spring Boot 标准的 @Value,@ConfigurationProperties 注解即可获取配置内容。动态配置刷新能力,则通过 Spring Cloud 标准的 @RefreshScope 机制实现。 64 | 65 | - 服务增加 polaris-config 依赖 66 | 67 | ```xml 68 | 69 | com.tencent.cloud 70 | spring-cloud-starter-tencent-polaris-config 71 | 72 | ``` 73 | 74 | - bootstrap.yaml 接入 polaris-config 75 | 76 | ```yaml 77 | spring: 78 | cloud: 79 | polaris: 80 | address: grpc://127.0.0.1:8081 81 | config: 82 | groups: 83 | - name: ${spring.application.name} 84 | files: "application" 85 | 86 | ``` 87 | 88 | > 特别注意: 这里需要配置在 bootstrap, spring-cloud-tencent 未适配 spring boot 最新的文件加载机制 89 | 90 | - 北极星控制台增加配置 91 | 92 | ![](https://minio.pigx.vip/oss/1655810261.png) 93 | 94 | ![](https://minio.pigx.vip/oss/1655810312.png) 95 | 96 | - 代码使用配置 97 | 98 | ``` 99 | @Value("${name:}") 100 | private String name; 101 | ``` 102 | 103 | ## 四、服务限流 104 | 105 | > > 服务限流是最常见的一种服务自我保护措施之一,防止流量洪峰打垮服务。Spring Cloud Tencent Rate Limit 模块内置了针对 Spring Web 和 Spring WebFlux 场景的限流 Filter,结合 Polaris 的限流功能帮忙业务快速接入限流能力。 106 | 107 | - 服务增加 polaris-ratelimit 依赖 108 | 109 | > 使用限流组件时添加 discovery ,方便在服务列表编辑 110 | 111 | ```xml 112 | 113 | com.tencent.cloud 114 | spring-cloud-starter-tencent-polaris-discovery 115 | 116 | 117 | com.tencent.cloud 118 | spring-cloud-starter-tencent-polaris-ratelimit 119 | 120 | ``` 121 | 122 | - 服务接入 polaris-ratelimit 123 | 124 | ```yaml 125 | spring: 126 | cloud: 127 | polaris: 128 | address: grpc://127.0.0.1:8091 129 | namespace: default 130 | ratelimit: 131 | reject-http-code: 403 132 | reject-request-tips: "lengleng test rate limit" 133 | ``` 134 | 135 | - 北极星控制台增加限流规则 136 | 137 | ![](https://minio.pigx.vip/oss/1655810598.png) 138 | 139 | ## 五、服务路由 140 | 141 | > > polaris 能够实现的路由形式较多元数据路由、就近路由、规则路由、自定义路由等形式,本文以元数据路由演示,如下图只会路由至相同元数据信息的服务 142 | 143 | ![](https://minio.pigx.vip/oss/1655811097.jpg) 144 | 145 | - 服务增加 polaris-router 依赖 146 | 147 | ``` 148 | 149 | com.tencent.cloud 150 | spring-cloud-starter-tencent-polaris-router 151 | 152 | ``` 153 | 154 | - 服务标记元数据 155 | 156 | ```yaml 157 | spring: 158 | cloud: 159 | polaris: 160 | address: grpc://127.0.0.1:8091 161 | tencent: 162 | metadata: 163 | content: 164 | version: local 165 | ``` 166 | 167 | ## 六、限流熔断 168 | 169 | > > 故障实例熔断是常见的一种容错保护机制。故障实例熔断能实现主调方迅速自动屏蔽错误率高或故障的服务实例,并启动定时任务对熔断实例进行探活。在达到恢复条件后对其进行半开恢复。在半开恢复后,释放少量请求去进行真实业务探测。并根据真实业务探测结果去判断是否完全恢复正常。 170 | 171 | ![](https://minio.pigx.vip/oss/1655811440.jpg) 172 | 173 | - 添加限流熔断相关的依赖 polaris-circuitbreaker 174 | 175 | ```xml 176 | 177 | com.tencent.cloud 178 | spring-cloud-starter-tencent-polaris-circuitbreaker 179 | 180 | 181 | 182 | org.springframework.cloud 183 | spring-cloud-starter-loadbalancer 184 | 185 | 186 | 187 | com.tencent.cloud 188 | spring-cloud-starter-tencent-polaris-discovery 189 | 190 | 191 | 192 | org.springframework.cloud 193 | spring-cloud-circuitbreaker-spring-retry 194 | 195 | 196 | 197 | org.springframework.cloud 198 | spring-cloud-starter-openfeign 199 | 200 | ``` 201 | 202 | - 提供 Feign 服务调用实现 203 | 204 | > spring-cloud-tencent 当前版本仅支持 feign 熔断 205 | 206 | ```java 207 | @FeignClient(contextId = "demoFeign", value = "lengleng-circuitbreaker-tencent-circuitbreaker-provider", 208 | fallback = DemoFeignFallback.class) 209 | public interface DemoFeign { 210 | @GetMapping("/provider") 211 | String get(@RequestParam String name); 212 | 213 | } 214 | ``` 215 | 216 | - 服务接入 polaris-circuitbreaker 217 | 218 | ```yaml 219 | spring: 220 | cloud: 221 | polaris: 222 | address: grpc://127.0.0.1:8091 223 | 224 | #开启断路器 225 | feign: 226 | circuitbreaker: 227 | enabled: true 228 | 229 | ``` 230 | 231 | - 编写熔断规则 polaris.yml 232 | 233 | ```yaml 234 | consumer: 235 | circuitBreaker: 236 | checkPeriod: 100ms 237 | chain: 238 | - errorCount 239 | - errorRate 240 | plugin: 241 | errorCount: 242 | continuousErrorThreshold: 1 243 | metricNumBuckets: 1 244 | errorRate: 245 | errorRateThreshold: 100 246 | metricStatTimeWindow: 1s 247 | requestVolumeThreshold: 1 248 | ``` 249 | 250 | > > 全文配套源码: [https://github.com/lltx/spring-cloud-tencent-demo](https://github.com/lltx/spring-cloud-tencent-demo "spring-cloud-tencent-demo") 251 | --------------------------------------------------------------------------------