feat: 拆分quickstart为consumer和provider 2个工程

pull/19/head
andrewshan 3 years ago
parent 7ed53b1b0a
commit a00a6480bb

@ -8,7 +8,7 @@
### 修改配置 ### 修改配置
修改bootstrap.yml修改后配置如下所示。其中${ip}和${port}为Polaris后端服务的IP地址与端口号。 在 polaris-quickstart-example/quickstart-provider 以及 polaris-quickstart-example/quickstart-consumer 两个项目中,修改bootstrap.yml修改后配置如下所示。其中${ip}和${port}为Polaris后端服务的IP地址与端口号。
```yaml ```yaml
spring: spring:
@ -21,15 +21,15 @@ spring:
### 启动样例 ### 启动样例
#### 启动应用 #### 启动Provider
- IDEA启动 - IDEA启动
找到 polaris-quickstart-example 项目的主类 EchoServiceApplication执行 main 方法启动样例。 找到 polaris-quickstart-example/quickstart-provider 项目的主类 EchoServerApplication执行 main 方法启动样例。
- Maven打包启动 - Maven打包启动
在```spring-cloud-tencent-examples/polaris-quickstart-example```下执行 在```polaris-quickstart-example/quickstart-provider```下执行
```sh ```sh
mvn clean package mvn clean package
@ -41,14 +41,42 @@ mvn clean package
java -jar ${app.jar} java -jar ${app.jar}
``` ```
启动应用,其中${app.jar}替换为对应的jar包名。 启动应用,其中`${app.jar}`替换为对应的jar包名。
#### 启动Consumer
- IDEA启动
找到 polaris-quickstart-example/quickstart-consumer 项目的主类 EchoClientApplication执行 main 方法启动样例。
- Maven打包启动
在```polaris-quickstart-example/quickstart-consumer```下执行
```sh
mvn clean package
```
然后找到生成的jar包运行
```
java -jar ${app.jar}
```
启动应用,其中`${app.jar}`替换为对应的jar包名。
### 验证 ### 验证
#### HTTP调用 #### HTTP调用
Consumer 和 Provider 启动端口都是随机生成的因此需要记录Consumer启动时候的端口
```
11:26:53 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): 58838 (http) with context path ''
```
执行http调用其中`${app.port}`替换为启动的端口。
```shell ```shell
curl -L -X GET 'http://localhost:47080/quickstart/feign?msg=hello_world'' curl -L -X GET 'http://localhost:${app.port}/echo?value=hello_world''
``` ```
预期返回值hello_world 预期返回值:`echo: hello_world`

@ -10,20 +10,13 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>polaris-quickstart-example</artifactId> <artifactId>Spring Cloud Tencent Polaris QuickStart Example</artifactId>
<name></name>
<packaging>pom</packaging>
<modules>
<module>quickstart-provider</module>
<module>quickstart-consumer</module>
</modules>
<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> </project>

@ -0,0 +1,37 @@
<?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 Polaris QuickStart Example</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>1.1.4.Hoxton.SR9-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>quickstart-consumer</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>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*/ */
package com.tencent.cloud.polaris.quickstart.example; package com.tencent.cloud.polaris.quickstart.consumer;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@ -25,9 +25,9 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication @SpringBootApplication
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients @EnableFeignClients
public class EchoServiceApplication { public class EchoClientApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(EchoServiceApplication.class, args); SpringApplication.run(EchoClientApplication.class, args);
} }
} }

@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*/ */
package com.tencent.cloud.polaris.quickstart.example; package com.tencent.cloud.polaris.quickstart.consumer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -24,22 +24,16 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/quickstart") @RequestMapping("/")
public class EchoController { public class EchoClientController {
@Autowired @Autowired
private EchoService echoService; private EchoServer echoServer;
@GetMapping("/echo") @GetMapping("/echo")
public String echo(@RequestParam String msg) { public String echo(@RequestParam String value) {
return "echo: " + msg; return echoServer.echo(value);
}
@GetMapping("/feign")
public String feign(@RequestParam String msg) {
return echoService.echo(msg);
} }
} }

@ -15,15 +15,15 @@
* specific language governing permissions and limitations under the License. * specific language governing permissions and limitations under the License.
*/ */
package com.tencent.cloud.polaris.quickstart.example; package com.tencent.cloud.polaris.quickstart.consumer;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(value = "EchoService") @FeignClient(value = "EchoServer")
public interface EchoService { public interface EchoServer {
@GetMapping("/quickstart/echo") @GetMapping("/quickstart/echo")
String echo(@RequestParam("msg") String msg); String echo(@RequestParam("value") String value);
} }

@ -0,0 +1,9 @@
server:
port: 0
spring:
application:
name: EchoClient
cloud:
polaris:
address: grpc://9.134.15.118:8091
# address: grpc://127.0.0.1:8091

@ -0,0 +1,33 @@
<?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>polaris-quickstart-example</artifactId>
<groupId>com.tencent.cloud</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>quickstart-provider</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>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -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.provider;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class EchoServerApplication {
public static void main(String[] args) {
SpringApplication.run(EchoServerApplication.class, args);
}
}

@ -0,0 +1,37 @@
/*
* 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.provider;
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;
/**
* main http controller for EchoService
*/
@RestController
@RequestMapping("/quickstart")
public class EchoServerController {
@GetMapping("/echo")
public String echo(@RequestParam(value = "value") String value) {
return "echo: " + value;
}
}

@ -0,0 +1,9 @@
server:
port: 0
spring:
application:
name: EchoServer
cloud:
polaris:
address: grpc://9.134.15.118:8091
# 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>

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