springcloud-OpenFeign服务接口调用(五)
2021-05-03 10:27
标签:级别 oca 区别 接口 nconf 编码 ping gap int springcloud-OpenFeign服务接口调用(五) 标签:级别 oca 区别 接口 nconf 编码 ping gap int 原文地址:https://www.cnblogs.com/binwenhome/p/13195672.html概述
OpenFeign服务调用
dependencies>
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-starter-openfeignartifactId>
dependency>
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-webartifactId>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-actuatorartifactId>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-devtoolsartifactId>
scope>runtimescope>
optional>trueoptional>
dependency>
dependency>
groupId>org.projectlombokgroupId>
artifactId>lombokartifactId>
optional>trueoptional>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-testartifactId>
scope>testscope>
dependency>
dependency>
groupId>springcloudgroupId>
artifactId>cloud-api-commonsartifactId>
version>1.0-SNAPSHOTversion>
scope>compilescope>
dependency>
dependencies>
server:
port: 80
eureka:
client:
register-with-eureka: false
service-url:
defaultZone: http://eureka7001.com:7001/eureka, http://eureka7002.com:7002/eureka
@EnableFeignClients
@SpringBootApplication
public class OrderFeignMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderFeignMain80.class, args);
}
}
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")
@Component
public interface PaymentFeignService {
@GetMapping(value = "/payment/get/{id}")
CommonResult
@RestController
@Slf4j
public class OrderFeignController {
@Resource
private PaymentFeignService paymentFeignService;
@GetMapping("/consumer/payment/get/{id}")
public CommonResult
OpenFeign超时控制
#设置Feign客户端超时时间(OpenFeign默认支持Ribbon)
ribbon:
#指的是建立连接所用的时间, 适用于网络状况正常的情况下, 两端连接所用的时间.
ReadTimeout: 5000
#指的是建立连接后从服务器读取到可用资源所用的时间
ConnectTimeout: 5000
OpenFeign日志打印功能
@Configuration
public class FeignConfig {
@Bean
Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
logging:
level:
springcloud.service.PaymentFeignService: debug
文章标题:springcloud-OpenFeign服务接口调用(五)
文章链接:http://soscw.com/index.php/essay/81750.html