Getting Started with Spring Cloud Tencent: Service Registration, Configuration, Rate Limiting, Circuit Breaking, and Metadata Transfer
This guide walks through installing and using Spring Cloud Tencent with Polaris, covering environment setup, Polaris deployment, Spring Boot project configuration, service registration, configuration center integration, rate‑limiting, circuit‑breaker features, and metadata transfer, while highlighting common pitfalls and practical code examples.
Spring Cloud Tencent is Tencent's open‑source one‑stop microservice solution that implements the standard Spring Cloud SPI and relies on the Polaris service‑discovery and governance platform.
The article begins by preparing a cloud server and deploying a single‑node Polaris instance, which includes four components (polaris‑console, polaris‑server, prometheus, pushgateway) and uses ports 8080, 8090, 8091, 9090, 9091 (configuration center uses 8093).
After downloading the Polaris Linux package, the steps are:
unzip polaris-standalone-release_v1.9.0.linux.amd64
cd polaris-standalone-release_v1.9.0.linux.amd64
bash install.shAccess the console at http:// :8080 with default credentials polaris/polaris .
Next, a Spring Boot project is created (Java 1.8, Spring Boot 2.3.2) and the following Maven dependencies are added:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>${spring-boot.version}</version>
</dependency>
... (other Spring Boot starters)
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId>
<version>1.5.2-Hoxton.SR9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>The bootstrap.yml file configures Polaris as both service registry and configuration center:
spring:
application:
name: spring-cloud-tencent-test
cloud:
polaris:
address: grpc://
:8091
namespace: default
config:
auto-refresh: trueRunning the application initially fails with a timeout because the required ports were not opened; after exposing the ports the service registers successfully.
Metadata can be defined in the configuration file, as command‑line arguments, or via environment variables prefixed with SCT_METADATA_CONTENT_ . Example YAML snippet:
spring:
cloud:
tencent:
metadata:
content:
idc: shanghai
env: dev1The configuration center module implements the Spring Cloud PropertySourceLoader SPI . Configuration files must be placed in bootstrap.yml (or related bootstrap-*.yml files) to be loaded during the bootstrap phase.
To add the Config Center dependency, include:
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-config</artifactId>
</dependency>After creating a configuration group in Polaris (named after the application) and adding a file such as application.yml , the values can be injected with @Value or @ConfigurationProperties . Dynamic refresh is enabled by setting spring.cloud.polaris.config.auto-refresh=true and annotating beans with @RefreshScope .
Rate limiting is added by including the dependency spring-cloud-starter-tencent-polaris-ratelimit and defining rules in the Polaris console (exact or regex matching, single‑node or distributed). When the limit is exceeded, Polaris returns a throttling response.
Circuit breaking is enabled via the dependency spring-cloud-starter-tencent-polaris-circuitbreaker and corresponding YAML configuration. Rules can be defined in Polaris either as YAML or JSON; the article shows screenshots of the rule UI.
Metadata transfer extends Feign to propagate custom tags. Static tags are defined in spring.cloud.tencent.metadata.transitive , while dynamic tags can be added in an interceptor by setting the header SCT-CUSTOM-METADATA . The required starter is spring-cloud-starter-tencent-metadata-transfer .
In summary, Spring Cloud Tencent provides registration, configuration, rate limiting, circuit breaking, and metadata transfer in a single framework, similar to Spring Cloud Alibaba, but with some integration quirks and fewer community resources.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.