OpenFeign是用来简化服务之间的调用的,通过JAVA接口和Spring MVC注解来定义API接口。
集成OpenFeign
引入依赖
<!-- openfeign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
开启功能
@EnableFeignClients
定义接口,FeignClient里面写上服务方的服务名
@Service
@FeignClient(value = "payment")
public interface PaymentService {
@PostMapping("pay")
String pay();
}
就跟普通service一样调用
@GetMapping("orderByFeign")
public String orderByFeign() {
String result = paymentService.pay();
log.info(result);
return "下单成功";
}
设置超时时间
#设置feign客户端超时时间
ribbon:
ReadTimeout: 10000 #读取内容超时时间
ConnectTimeout: 5000 #建立连接时间超时时间
本文介绍如何使用OpenFeign简化微服务间的调用,包括集成步骤、定义API接口及配置超时时间等关键操作。
1224

被折叠的 条评论
为什么被折叠?



