✨ 远程调用-超时控制-默认效果
This commit is contained in:
parent
41f905af9e
commit
42f1c00231
|
@ -1,3 +0,0 @@
|
||||||
server:
|
|
||||||
port: 8000
|
|
||||||
|
|
|
@ -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
|
|
@ -6,6 +6,8 @@ spring:
|
||||||
name: service-order
|
name: service-order
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
active: dev
|
||||||
|
include:
|
||||||
|
- feign
|
||||||
cloud:
|
cloud:
|
||||||
nacos:
|
nacos:
|
||||||
server-addr: 192.168.95.135:8848
|
server-addr: 192.168.95.135:8848
|
||||||
|
|
|
@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/product")
|
@RequestMapping("/api/product")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -19,6 +21,11 @@ public class ProductController {
|
||||||
@Operation(summary = "根据id查询商品")
|
@Operation(summary = "根据id查询商品")
|
||||||
@GetMapping("{id}")
|
@GetMapping("{id}")
|
||||||
public Product getProduct(@PathVariable("id") Long productId) {
|
public Product getProduct(@PathVariable("id") Long productId) {
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(6);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
return productService.getProductById(productId);
|
return productService.getProductById(productId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue