From 42b7c7a0ae59d21d37d113ca3fd9ec88d897f317 Mon Sep 17 00:00:00 2001 From: Fishtail <49390359+fuyuwei01@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:56:06 +0800 Subject: [PATCH] feat: add spring cloud gateway mvc example (#1367) --- CHANGELOG.md | 3 +- .../quickstart-example/pom.xml | 1 + .../quickstart-gateway-mvc-service/pom.xml | 57 +++++++++++++++++++ .../gatewaymvc/FallbackController.java | 37 ++++++++++++ .../QuickstartGatewayMvcApplication.java | 35 ++++++++++++ .../src/main/resources/application.yml | 30 ++++++++++ 6 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/pom.xml create mode 100644 spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/java/com/tencent/cloud/quickstart/gatewaymvc/FallbackController.java create mode 100644 spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/java/com/tencent/cloud/quickstart/gatewaymvc/QuickstartGatewayMvcApplication.java create mode 100644 spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/resources/application.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ae2c3758..f581f4e83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,4 +15,5 @@ - [feat:upgrade jacoco version.](https://github.com/Tencent/spring-cloud-tencent/pull/1310) - [fix:fix no registry when lossless is disabled.](https://github.com/Tencent/spring-cloud-tencent/pull/1312) - [fix:fix the ratelimit bug for 2023](https://github.com/Tencent/spring-cloud-tencent/pull/1316) -- [fix:update spring boot version](https://github.com/Tencent/spring-cloud-tencent/pull/1333) \ No newline at end of file +- [fix:update spring boot version](https://github.com/Tencent/spring-cloud-tencent/pull/1333) +- [feat:add scg-mvc example](https://github.com/Tencent/spring-cloud-tencent/pull/1367) \ No newline at end of file diff --git a/spring-cloud-tencent-examples/quickstart-example/pom.xml b/spring-cloud-tencent-examples/quickstart-example/pom.xml index 07bd50ffc..644d4a4ae 100644 --- a/spring-cloud-tencent-examples/quickstart-example/pom.xml +++ b/spring-cloud-tencent-examples/quickstart-example/pom.xml @@ -19,5 +19,6 @@ quickstart-caller-service quickstart-callee-service-a quickstart-callee-service-b + quickstart-gateway-mvc-service \ No newline at end of file diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/pom.xml b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/pom.xml new file mode 100644 index 000000000..33a37a878 --- /dev/null +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/pom.xml @@ -0,0 +1,57 @@ + + + + quickstart-example + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + quickstart-gateway-mvc-service + Quickstart Gateway MVC Service + + + + com.tencent.cloud + spring-cloud-starter-tencent-all + + + + org.springframework.cloud + spring-cloud-starter-gateway-mvc + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar + + + + + + + diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/java/com/tencent/cloud/quickstart/gatewaymvc/FallbackController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/java/com/tencent/cloud/quickstart/gatewaymvc/FallbackController.java new file mode 100644 index 000000000..b72dc4f6e --- /dev/null +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/java/com/tencent/cloud/quickstart/gatewaymvc/FallbackController.java @@ -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.quickstart.gatewaymvc; + +import reactor.core.publisher.Mono; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * FallbackController. + * + * sean yu + */ +@RestController +public class FallbackController { + + @GetMapping("/polaris-fallback") + Mono getFallback() { + return Mono.just("fallback: trigger the refuse for service caller."); + } +} diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/java/com/tencent/cloud/quickstart/gatewaymvc/QuickstartGatewayMvcApplication.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/java/com/tencent/cloud/quickstart/gatewaymvc/QuickstartGatewayMvcApplication.java new file mode 100644 index 000000000..5fdd436f0 --- /dev/null +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/java/com/tencent/cloud/quickstart/gatewaymvc/QuickstartGatewayMvcApplication.java @@ -0,0 +1,35 @@ +/* + * 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.quickstart.gatewaymvc; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Quickstart SCG application. + * + * @author Haotian Zhang + */ +@SpringBootApplication +public class QuickstartGatewayMvcApplication { + + public static void main(String[] args) { + SpringApplication.run(QuickstartGatewayMvcApplication.class, args); + } + +} diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/resources/application.yml b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/resources/application.yml new file mode 100644 index 000000000..7a98796f7 --- /dev/null +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/resources/application.yml @@ -0,0 +1,30 @@ +server: + port: 48085 +spring: + application: + name: QuickStartGatewayMvcService + config: + import: optional:polaris + cloud: + polaris: + address: grpc://119.91.66.223:8091 + namespace: default + enabled: true + contract: + exposure: true + report: + enabled: true + stat: + enabled: true + port: 28085 + gateway: + mvc: + routes: + - id: QuickstartCallerService + uri: lb://QuickstartCallerService + predicates: + - Path=/QuickstartCallerService/** + filters: + - StripPrefix=1 + +