欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

spring boot项目配置RestTemplate超时时长

程序员文章站 2022-04-28 15:56:59
配置类: 调用: ......

配置类:

@configuration
public class feignconfiguration {
    @bean(name="remoteresttemplate")
    public  resttemplate resttemplate(){
        simpleclienthttprequestfactory requestfactory = new simpleclienthttprequestfactory();
        requestfactory.setconnecttimeout(5000);
        requestfactory.setreadtimeout(3500);
        resttemplate resttemplate = new resttemplate(requestfactory);
        return resttemplate;
    }
}

调用:

@service
@slf4j
public class slcustomercreditsettingproductserviceimpl implements slcustomercreditsettingproductservice {
    @autowired
    private slcustomercreditsettingproductfeignclient slcustomercreditsettingproductfeignclient;
    @autowired
    @qualifier(value = "remoteresttemplate")
    private resttemplate resttemplate;
    @value("${crb_hub_url}")
    private string crbhuburl;
    @autowired
    private mqserverservice mqserverservice;

    @override
    public list<slcustomercreditsettingproductrespvo> getcustomercreditsettingproductrespvo(userinfo userinfo) throws openhttpexection{
        slcustomercreditsettingproductqueryvo slcustomercreditsettingproductqueryvo = new slcustomercreditsettingproductqueryvo();
        slcustomercreditsettingproductqueryvo.setcorporationid(userinfo.getcorporationid());
        slcustomercreditsettingproductqueryvo.setcustomerid(userinfo.getcustomerid());
        slcustomercreditsettingproductqueryvo.seteffectiveenddate(userinfo.getmakedate());
        slcustomercreditsettingproductqueryvo.setmakedate(userinfo.getmakedate());
        slcustomercreditsettingproductqueryvo.setregioncode(userinfo.getregioncode());
        list<slcustomercreditsettingproductrespvo> slcustomercreditsettingproductrespvos = lists.newarraylist();

        parameterizedtypereference<list<customercreditsettingproduct>> typeref = new parameterizedtypereference<list<customercreditsettingproduct>>() {};
        responseentity<list<customercreditsettingproduct>> customercreditsettingproductrespvos;
        //post调用外部接口
        try {
            customercreditsettingproductrespvos = resttemplate.exchange(
            crbhuburl+"/customercreditsettingproductapicontroller/findbycustomeridandcorporationid",
            httpmethod.post,
            new httpentity<>(slcustomercreditsettingproductqueryvo),
            typeref);
        }catch (exception e){
            throw new openhttpexection(e.getmessage());
        }
        if(collectionutils.isnotempty(customercreditsettingproductrespvos.getbody())) {
            for (customercreditsettingproduct o : customercreditsettingproductrespvos.getbody()) {
                slcustomercreditsettingproductrespvo slcustomercreditsettingproductrespvo = new slcustomercreditsettingproductrespvo();
                beanutils.copyproperties(o, slcustomercreditsettingproductrespvo);
                slcustomercreditsettingproductrespvos.add(slcustomercreditsettingproductrespvo);
            }
            //mq发送数据
            synslcustomercreditsettingproduct synslcustomercreditsettingproduct = new synslcustomercreditsettingproduct();
            synslcustomercreditsettingproduct.setcustomercreditsettingproducts(customercreditsettingproductrespvos.getbody());
            synslcustomercreditsettingproduct.setslcustomercreditsettingproductqueryvo(slcustomercreditsettingproductqueryvo);
            try {
                mqserverservice.sendloopcedit(synslcustomercreditsettingproduct);
            }catch (exception e){
                e.printstacktrace();
                log.error("同步客户信用体系设定数据到本地数据库失败!");
            }
        }
        return slcustomercreditsettingproductrespvos;
    }
}