From 42f1c00231521d39c0e9face91d644d0e8647725 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Mon, 26 May 2025 18:30:16 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E8=BF=9C=E7=A8=8B=E8=B0=83?= =?UTF-8?q?=E7=94=A8-=E8=B6=85=E6=97=B6=E6=8E=A7=E5=88=B6-=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yaml | 3 --- .../src/main/resources/application-feign.yaml | 16 ++++++++++++++++ .../src/main/resources/application.yaml | 2 ++ .../service/controller/ProductController.java | 7 +++++++ 4 files changed, 25 insertions(+), 3 deletions(-) delete mode 100644 cloud-demo/services/service-order/src/main/resources/application-dev.yaml create mode 100644 cloud-demo/services/service-order/src/main/resources/application-feign.yaml diff --git a/cloud-demo/services/service-order/src/main/resources/application-dev.yaml b/cloud-demo/services/service-order/src/main/resources/application-dev.yaml deleted file mode 100644 index 8ba16c0..0000000 --- a/cloud-demo/services/service-order/src/main/resources/application-dev.yaml +++ /dev/null @@ -1,3 +0,0 @@ -server: - port: 8000 - diff --git a/cloud-demo/services/service-order/src/main/resources/application-feign.yaml b/cloud-demo/services/service-order/src/main/resources/application-feign.yaml new file mode 100644 index 0000000..7d17590 --- /dev/null +++ b/cloud-demo/services/service-order/src/main/resources/application-feign.yaml @@ -0,0 +1,16 @@ +spring: + cloud: + openfeign: + client: + config: + # 对所有配置 + default: + logger-level: full + connect-timeout: 1000 + read-timeout: 1000 # 最多等待对方 5s + + # 对 service-product 单独设置 + service-product: + logger-level: full + connect-timeout: 3000 + read-timeout: 5000 # 最多等待对方 5s \ No newline at end of file diff --git a/cloud-demo/services/service-order/src/main/resources/application.yaml b/cloud-demo/services/service-order/src/main/resources/application.yaml index 4b9f087..cce3540 100644 --- a/cloud-demo/services/service-order/src/main/resources/application.yaml +++ b/cloud-demo/services/service-order/src/main/resources/application.yaml @@ -6,6 +6,8 @@ spring: name: service-order profiles: active: dev + include: + - feign cloud: nacos: server-addr: 192.168.95.135:8848 diff --git a/cloud-demo/services/service-product/src/main/java/cn/bunny/service/controller/ProductController.java b/cloud-demo/services/service-product/src/main/java/cn/bunny/service/controller/ProductController.java index 9e5e75a..e036da0 100644 --- a/cloud-demo/services/service-product/src/main/java/cn/bunny/service/controller/ProductController.java +++ b/cloud-demo/services/service-product/src/main/java/cn/bunny/service/controller/ProductController.java @@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.concurrent.TimeUnit; + @RestController @RequestMapping("/api/product") @RequiredArgsConstructor @@ -19,6 +21,11 @@ public class ProductController { @Operation(summary = "根据id查询商品") @GetMapping("{id}") public Product getProduct(@PathVariable("id") Long productId) { + try { + TimeUnit.SECONDS.sleep(6); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } return productService.getProductById(productId); } }