远程调用-超时控制-默认效果

This commit is contained in:
bunny 2025-05-26 18:30:16 +08:00
parent 41f905af9e
commit 42f1c00231
4 changed files with 25 additions and 3 deletions

View File

@ -1,3 +0,0 @@
server:
port: 8000

View File

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

View File

@ -6,6 +6,8 @@ spring:
name: service-order
profiles:
active: dev
include:
- feign
cloud:
nacos:
server-addr: 192.168.95.135:8848

View File

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