1.什么是openfegin:声明式的web服务的客户端。之前是在消费者服务器中通过reestTemplate和ribbon对生产者服务进行负载调用。现在只需要在接口上配置对应的注解,并在启动类上添加启动的注解即可。
@Component
@FeignClient(value = "SPRING-CLOUD-PAYMENT")
public interface FindConsume {
@GetMapping(value = "/find")
R find(@RequestParam(value = "goodId") Integer goodId);
}
@SpringBootApplication
@EnableFeignClients
public class ConsumerFeginApplication {
public static void main(String[] args) {
SpringApplication.run(ConsumerFeginApplication.class,args);
}
}
2.openfegin的网络延迟时间设置与后端业务逻辑处理时间设置
模拟时间超时
@GetMapping(value = "/timeOut")
public String timeOut(){
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "ok";
}
}
在订单服务中添加配置
ribbon:
ReadTimeout: 5000
ConnectTimeout: 5000
3.fegin自带日志管理。
选择Full级别的日志
@Configuration
public class feginConfig {
@Bean
public Logger.Level logger(){
return Logger.Level.FULL;
}
}
配置文件设置书写日志的包的地址
logging:
level:
com.shuai.service.FindConsume: debug
网友评论