广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Spring Feign超时设置深入了解
  • 564
分享到

Spring Feign超时设置深入了解

Spring Feign超时设置Spring Feign超时时间设置 2023-03-19 17:03:39 564人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

目录Feign其他功能-超时设置Feign其他功能-日志记录修改consumerFeign其他功能-超时设置 Feign 底层依赖于 Ribbon 实现负载均衡和远程调用。Ribbo

Feign其他功能-超时设置

  • Feign 底层依赖于 Ribbon 实现负载均衡和远程调用。
  • Ribbon默认1秒超时。

超时配置:

ribbon:

ConnectTimeout: 1000 #连接超时时间,毫秒

ReadTimeout: 1000 #逻辑处理超时时间,毫秒

在feign-consumer中设置超时时间(具体代码看上 Feign的快速入门)

server:
  port: 9000

eureka:
  instance:
    hostname: localhost # 主机名
  client:
    service-url:
      defaultZone: Http://localhost:8761/eureka
spring:
  application:
    name: feign-consumer # 设置当前应用的名称。将来会在eureka中Application显示。将来需要使用该名称来获取路径

#设置Ribbon的超时时间
ribbon:
  ConnectTimeout: 1000 #链接超时时间,默认1s
  ReadTimeout: 3000 #逻辑处理的超时时间 默认1s

provider超时2s测试

Goods goods = goodsservice.findOne(id);
//当前现场睡眠2秒
try {
    Thread.sleep( millis: 2000);
}catch (InterruptedException e) {
    e.printStackTrace(); //java.net.SocketTimeoutException: Read timed out
}
goods.setTitle(goods.getTitle() + ":" + port);//将端口号,设置

Feign其他功能-日志记录

Feign 只能记录 debug 级别的日志信息。

logging: 
     level:   
          com.itheima: debug //包名

定义Feign日志级别Bean

@Bean
Logger.Level feignLoggerLevel() {    
		return Logger.Level.FULL;
		}

启用该Bean:

@FeignClient(configuration = XxxConfig.class)

修改consumer

#设置当前的日志级别 debug,feign 只支持记录debug级别的日志
logging:
  level:
    com.itheima: debug

package com.itheima.consumer.config;
import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignLoGConfig {
    
    @Bean
    public Logger.Level level(){
        return Logger.Level.FULL;
    }
}
package com.itheima.consumer.feign;
import com.itheima.consumer.config.FeignLogConfig;
import com.itheima.consumer.domain.Goods;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.WEB.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

@FeignClient(value = "FEIGN-PROVIDER",configuration = FeignLogConfig.class)
public interface GoodsFeignClient {
    @GetMapping("/goods/findOne/{id}")
    public Goods findGoodsById(@PathVariable("id") int id);
}

到此这篇关于Spring Feign超时设置深入了解的文章就介绍到这了,更多相关Spring Feign超时设置内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: Spring Feign超时设置深入了解

本文链接: https://www.lsjlt.com/news/200327.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作