spring boot项目配置RestTemplate超时时长
生活随笔
收集整理的這篇文章主要介紹了
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 {@Autowiredprivate SlCustomerCreditSettingProductFeignClient slCustomerCreditSettingProductFeignClient;@Autowired@Qualifier(value = "remoteRestTemplate")private RestTemplate restTemplate;@Value("${crb_hub_url}")private String crbHubUrl;@Autowiredprivate MQServerService mqServerService;@Overridepublic 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;} }?
轉載于:https://www.cnblogs.com/kangchen/p/10750152.html
總結
以上是生活随笔為你收集整理的spring boot项目配置RestTemplate超时时长的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP的 preg_match_all
- 下一篇: 性能测试入门(六)windows及Lin