开发技术-springboot调用第三方接口超时

1.项目使用的是OpenFeign调用的第三方接口,但是报出了超时的问题。

查了一些资料,有说需要设置ribbon的参数:

ribbon:  
  ReadTimeout: 60000  
  ConnectTimeout: 60000

不过这个并不管用,ribbon是负载均衡使用的,对自己的服务(注册在eureka上的),可以起到作用。对于第三方并不起作用。

2.老王查了资料,建议换一个http请求的框架,例如forest。然后做了一个demo

1)引入依赖

        
            com.dtflys.forest
            forest-spring-boot-starter
            1.5.0-RC7
        

2)接口代码

package com.example.demo.api;

import com.dtflys.forest.annotation.BaseRequest;
import com.dtflys.forest.annotation.Get;
import com.dtflys.forest.annotation.LogEnabled;

@BaseRequest(
        baseURL = "${user_url}",
        headers = {
                "Content-Type:application/json;charset=utf-8"
        },
        timeout = 10000, // 请求时间
        retryCount = 1 // 请求重试次数
)
@LogEnabled(logResponseContent = true)
public interface DemoClient {
        @Get(url = "http://www.baidu.com")
        String accessBaidu();
}

3.这只是个简单的例子,

在查询资料的过程中,有个写的很详细,开个门:Forest 使用简介

另附:官网地址

再附:官网讲的很明白

你可能感兴趣的:(Java开发,java)