From 45fcf3ce0ba290ea4b686d415e826b663767b8da Mon Sep 17 00:00:00 2001 From: fuyuwei01 Date: Wed, 7 Aug 2024 14:50:18 +0800 Subject: [PATCH] feat: add spring cloud gateway mvc example --- .../quickstart-example/pom.xml | 1 + .../quickstart-gateway-mvc-service/pom.xml | 62 +++++++++++++++++++ .../gatewaymvc/FallbackController.java | 37 +++++++++++ .../QuickstartGatewayMvcApplication.java | 35 +++++++++++ .../src/main/resources/application.yml | 35 +++++++++++ 5 files changed, 170 insertions(+) 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/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..0ff284753 --- /dev/null +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/pom.xml @@ -0,0 +1,62 @@ + + + + quickstart-example + com.tencent.cloud + ${revision} + ../pom.xml + + 4.0.0 + + quickstart-gateway-mvc-service + Quickstart Gateway Service + + + + com.tencent.cloud + spring-cloud-starter-tencent-all + + + + com.tencent.cloud + spring-cloud-tencent-gateway-plugin + + + + 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..4d2388bb4 --- /dev/null +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-mvc-service/src/main/resources/application.yml @@ -0,0 +1,35 @@ +server: + port: 48080 +spring: + application: + name: QuickStartGatewayService + config: + import: optional:polaris + cloud: + tencent: + plugin: + router: + feature-env: + enabled: true + polaris: + address: grpc://119.91.66.223:8091 + namespace: default + enabled: true + contract: + exposure: true + report: + enabled: true + stat: + enabled: true + port: 28081 + gateway: + mvc: + routes: + - id: QuickstartCallerService + uri: lb://QuickstartCallerService + predicates: + - Path=/QuickstartCallerService/** + filters: + - StripPrefix=1 + +