配置类:
@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; } }