Merge pull request #17 from andrewshan/main

support quickstart example and documents
pull/25/head
liaochuntao 3 years ago committed by GitHub
commit 91ad047838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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。
````
<dependencyManagement>
@ -46,8 +39,7 @@ Spring Cloud Tencent 使用 Maven 来构建,最快的使用方式是将本项
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-tencent-dependencies</artifactId>
<!--版本号需修改成实际依赖的版本号-->
<version>${version}</version>
<version>1.1.4.Hoxton.SR9</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -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)
## 版本号规范

@ -63,7 +63,7 @@
<properties>
<revision>1.1.4.Hoxton.SR9-SNAPSHOT</revision>
<polaris.version>1.2.0</polaris.version>
<polaris.version>1.2.1</polaris.version>
<tomcat.version>10.0.0-M6</tomcat.version>
<powermock.version>2.0.0</powermock.version>

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

@ -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''
```
expecthello_world

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-cloud-tencent-examples</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>polaris-quickstart-example</artifactId>
<dependencies>
<dependency>
<artifactId>spring-cloud-starter-tencent-polaris-discovery</artifactId>
<groupId>com.tencent.cloud</groupId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
</project>

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

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

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

@ -0,0 +1,9 @@
server:
session-timeout: 1800
port: 47080
spring:
application:
name: EchoService
cloud:
polaris:
address: grpc://127.0.0.1:8091

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

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
<contextName>logback</contextName>
<!--输出到控制台-->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!--按天生成日志-->
<appender name="logFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<Prudent>true</Prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>
applog/%d{yyyy-MM-dd}/%d{yyyy-MM-dd}.log
</FileNamePattern>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{yyyy-MM-dd HH:mm:ss} -%msg%n
</Pattern>
</layout>
</appender>
<root level="info">
<appender-ref ref="console"/>
<appender-ref ref="logFile"/>
</root>
</configuration>

@ -20,6 +20,7 @@
<module>polaris-ratelimit-example</module>
<module>polaris-circuitbreaker-example</module>
<module>polaris-gateway-example</module>
<module>polaris-quickstart-example</module>
</modules>
<properties>

@ -40,7 +40,7 @@
<!--依赖resCache插件-->
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>resource-cache-memory</artifactId>
<artifactId>registry-memory</artifactId>
</dependency>
<!--依赖flowCache插件-->

Loading…
Cancel
Save