diff --git a/README-zh.md b/README-zh.md index d1248534..500d0573 100644 --- a/README-zh.md +++ b/README-zh.md @@ -8,23 +8,18 @@ Spring Cloud Tencent包含了分布式应用微服务开发过程中所需的组件,基于 Spring Cloud 框架的开发者可以使用这些组件快速进行分布式应用的开发。 -在Spring Cloud Tencent的基础上,您只需要添加少量配置,就可以将 Spring Cloud 应用接入腾讯云微服务解决方案,通过腾讯云中间件来迅速搭建分布式应用系统。 - ## 主要功能 * **服务注册与发现**:基于 Spring Cloud Common的标准进行微服务的注册与发现。 * **服务路由与负载均衡**:基于 Ribbon 的接口标准,提供场景更丰富的动态路由以及负载均衡的能力。 * **故障节点熔断**:提供故障节点的熔断剔除以及主/被动探测恢复的能力,保证分布式服务的可靠性。 * **服务限流**:支持微服务被调接入层和网关主动调用的限流功能,保证后台微服务稳定性,可通过控制台动态配置规则,及查看流量监控数据。 -* **元数据传递**:支持网关和微服务之间的元数据传递。 - -## 组件 - -**[Polaris](https://github.com/PolarisMesh/polaris)**:北极星云原生的服务治理平台,解决远程调用的服务注册发现、动态路由、负载均衡和容错问题。 ## 如何构建 -* master 分支对应的是 Spring Cloud Hoxton,最低支持 JDK 1.8。 +* [2020.0.x](https://github.com/Tencent/spring-cloud-tencent/tree/2020.0.x)分支对应的是 Spring Cloud 2020.0版本,编译环境最低支持JDK 1.8。 +* [main](https://github.com/Tencent/spring-cloud-tencent/tree/main) 分支对应的是 Spring Cloud Hoxton版本,编译环境最低支持JDK 1.8。 +* [greenwich](https://github.com/Tencent/spring-cloud-tencent/tree/greenwich) 分支对应的是 Spring Cloud Greenwich版本,编译环境最低支持JDK 1.8。 Spring Cloud Tencent 使用 Maven 来构建,最快的使用方式是将本项目 clone 到本地,然后执行以下命令: ```bash @@ -37,8 +32,6 @@ Spring Cloud Tencent 使用 Maven 来构建,最快的使用方式是将本项 ### 如何引入依赖 在 dependencyManagement 中添加如下配置,然后在 dependencies 中添加自己所需使用的依赖即可使用。 -与此同时,您需要注意Spring Cloud Tencent对应的Spring Cloud版本,进而对应到的Spring Boot版本。 -例如Spring Cloud Tencent的1.0.1.Hoxton.SR9对应Spring Cloud Hoxton版本,需要使用Spring Boot 2.3.x。 ```` @@ -46,8 +39,7 @@ Spring Cloud Tencent 使用 Maven 来构建,最快的使用方式是将本项 com.tencent.cloud spring-cloud-tencent-dependencies - - ${version} + 1.1.4.Hoxton.SR9 pom import @@ -61,15 +53,17 @@ Spring Cloud Tencent 项目包含了一个子模块spring-cloud-tencent-examples Example 列表: -- [Polaris Discovery Example](spring-cloud-tencent-examples/polaris-discovery-example/README-zh.md) - -- [Polaris CircuitBreaker Example](spring-cloud-tencent-examples/polaris-circuitbreaker-example/README-zh.md) - -- [Polaris RateLimit Example](spring-cloud-tencent-examples/polaris-ratelimit-example/README-zh.md) - -- [Polaris Gateway Example](spring-cloud-tencent-examples/polaris-gateway-example/README-zh.md) - -更加详细的使用方法参考 [使用polaris-java](https://github.com/polarismesh/website/blob/main/docs/zh/doc/%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/%E4%BD%BF%E7%94%A8polaris-java.md). +- [PolarisMesh](https://github.com/polarismesh)接入相关的样例: + + - [快速入门](spring-cloud-tencent-examples/polaris-quickstart-example/README-zh.md) + + - [服务发现](spring-cloud-tencent-examples/polaris-discovery-example/README-zh.md) + + - [故障熔断](spring-cloud-tencent-examples/polaris-circuitbreaker-example/README-zh.md) + + - [限流](spring-cloud-tencent-examples/polaris-ratelimit-example/README-zh.md) + + - [网关](spring-cloud-tencent-examples/polaris-gateway-example/README-zh.md) ## 版本号规范 diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml index 7922fa66..ab31b0cd 100644 --- a/spring-cloud-tencent-dependencies/pom.xml +++ b/spring-cloud-tencent-dependencies/pom.xml @@ -63,7 +63,7 @@ 1.1.4.Hoxton.SR9-SNAPSHOT - 1.2.0 + 1.2.1 10.0.0-M6 2.0.0 diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/README-zh.md b/spring-cloud-tencent-examples/polaris-quickstart-example/README-zh.md new file mode 100644 index 00000000..c09e8392 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/README-zh.md @@ -0,0 +1,54 @@ +# Spring Cloud Polaris Quickstart example + +## 样例简介 + +本样例将介绍如何使应用快速接入Spring Cloud Tencent。 + +## 使用说明 + +### 修改配置 + +修改bootstrap.yml,修改后配置如下所示。其中,${ip}和${port}为Polaris后端服务的IP地址与端口号。 + +```yaml +spring: + application: + name: EchoService + cloud: + polaris: + address: grpc://${ip}:${port} +``` + +### 启动样例 + +#### 启动应用 + +- IDEA启动 + +找到 polaris-quickstart-example 项目的主类 EchoServiceApplication,执行 main 方法启动样例。 + +- Maven打包启动 + +在```spring-cloud-tencent-examples/polaris-quickstart-example```下执行 + +```sh +mvn clean package +``` + +然后找到生成的jar包,运行 + +``` +java -jar ${app.jar} +``` + +启动应用,其中${app.jar}替换为对应的jar包名。 + +### 验证 + +#### HTTP调用 + +```shell +curl -L -X GET 'http://localhost:47080/quickstart/feign?msg=hello_world'' +``` + +预期返回值:hello_world \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/README.md b/spring-cloud-tencent-examples/polaris-quickstart-example/README.md new file mode 100644 index 00000000..98d36bcf --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/README.md @@ -0,0 +1,54 @@ +# Spring Cloud Polaris Quickstart example + +## Example Introduction + +This example shows how to make application integrated with spring-cloud-tencent rapidly. + +## Instruction + +### Configuration + +Modify bootstrap.yml, ${ip} and ${port} is the address of polaris server. + +```yaml +spring: + application: + name: EchoService + cloud: + polaris: + address: grpc://${ip}:${port} +``` + +### Launching Example + +#### Launching Application + +- Start in IDEA + +Find main class EchoServiceApplication in project polaris-quickstart-example, and execute the main method. + +- Start by fatjar + +Run build command in ```spring-cloud-tencent-examples/polaris-quickstart-example```: + +```sh +mvn clean package +``` + +find the generated fatjar, run: + +``` +java -jar ${app.jar} +``` + +${app.jar} replace to the built jar name. + +### Verify + +#### Invoke by http call + +```shell +curl -L -X GET 'http://localhost:47080/quickstart/feign?msg=hello_world'' +``` + +expect:hello_world \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/pom.xml b/spring-cloud-tencent-examples/polaris-quickstart-example/pom.xml new file mode 100644 index 00000000..d2ddebca --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/pom.xml @@ -0,0 +1,29 @@ + + + + spring-cloud-tencent-examples + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + polaris-quickstart-example + + + + spring-cloud-starter-tencent-polaris-discovery + com.tencent.cloud + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoController.java b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoController.java new file mode 100644 index 00000000..643bfe89 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoController.java @@ -0,0 +1,45 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.quickstart.example; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/quickstart") +public class EchoController { + + @Autowired + private EchoService echoService; + + @GetMapping("/echo") + public String echo(@RequestParam String msg) { + return "echo: " + msg; + } + + @GetMapping("/feign") + public String feign(@RequestParam String msg) { + return echoService.echo(msg); + } + +} + + diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoService.java b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoService.java new file mode 100644 index 00000000..27a25b63 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoService.java @@ -0,0 +1,29 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.quickstart.example; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@FeignClient(value = "EchoService") +public interface EchoService { + + @GetMapping("/quickstart/echo") + String echo(@RequestParam("msg") String msg); +} diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoServiceApplication.java b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoServiceApplication.java new file mode 100644 index 00000000..e0990673 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/java/com/tencent/cloud/polaris/quickstart/example/EchoServiceApplication.java @@ -0,0 +1,33 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.quickstart.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableFeignClients +public class EchoServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(EchoServiceApplication.class, args); + } +} diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/bootstrap.yml new file mode 100644 index 00000000..0b6e763d --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/bootstrap.yml @@ -0,0 +1,9 @@ +server: + session-timeout: 1800 + port: 47080 +spring: + application: + name: EchoService + cloud: + polaris: + address: grpc://127.0.0.1:8091 \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/log4j.properties b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/log4j.properties new file mode 100644 index 00000000..9e520cb7 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/log4j.properties @@ -0,0 +1,15 @@ +log4j.rootLogger=DEBUG,console,FILE + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.threshold=INFO +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} [%5p] - %c -%F(%L) -%m%n + +log4j.appender.FILE=org.apache.log4j.RollingFileAppender +log4j.appender.FILE.Append=true + +log4j.appender.FILE.File=applog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log +log4j.appender.FILE.Threshold=INFO +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d{yyyy-MM-dd HH\:mm\:ss} [%5p] - %c -%F(%L) -%m%n +log4j.appender.FILE.MaxFileSize=10MB \ No newline at end of file diff --git a/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/logback-spring.xml b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..57f025c4 --- /dev/null +++ b/spring-cloud-tencent-examples/polaris-quickstart-example/src/main/resources/logback-spring.xml @@ -0,0 +1,31 @@ + + + logback + + + + %d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n + + + + + + true + + + applog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log + + + + + %d{yyyy-MM-dd HH:mm:ss} -%msg%n + + + + + + + + + + diff --git a/spring-cloud-tencent-examples/pom.xml b/spring-cloud-tencent-examples/pom.xml index f198c04c..34e709ec 100644 --- a/spring-cloud-tencent-examples/pom.xml +++ b/spring-cloud-tencent-examples/pom.xml @@ -20,6 +20,7 @@ polaris-ratelimit-example polaris-circuitbreaker-example polaris-gateway-example + polaris-quickstart-example diff --git a/spring-cloud-tencent-starters/spring-cloud-tencent-polaris-context/pom.xml b/spring-cloud-tencent-starters/spring-cloud-tencent-polaris-context/pom.xml index 19bfeccd..f8455a28 100644 --- a/spring-cloud-tencent-starters/spring-cloud-tencent-polaris-context/pom.xml +++ b/spring-cloud-tencent-starters/spring-cloud-tencent-polaris-context/pom.xml @@ -40,7 +40,7 @@ com.tencent.polaris - resource-cache-memory + registry-memory