• spring boot项目配置RestTemplate超时时长


    配置类:

    @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;
        }
    }
  • 相关阅读:
    20160227.CCPP体系详解(0037天)
    MinerUtil.java 爬虫工具类
    MinerUrl.java 解析页面后存储URL类
    MinerThreadPool.java 线程池
    MinerStoreThread.java 存储线程
    MinerQueue.java 访问队列
    MinerMonitorThread.java 监控线程
    MinerHtmlThread.java 爬取页面线程
    上班跟打DotA感觉差不多?姑娘你没事儿吧
    7月3日云栖精选夜读:强大的PyTorch:10分钟让你了解深度学习领域新流行的框架
  • 原文地址:https://www.cnblogs.com/kangchen/p/10750152.html
Copyright © 2020-2023  润新知