zoukankan      html  css  js  c++  java
  • 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;
        }
    }
  • 相关阅读:
    安全机制
    Service
    ubuntu 16.4 安装配置IK6.3.2
    ubuntu openstack windows 镜像制作
    openstack RuntimeError: Unable to create a new session key. It is likely that the cache
    千帆过尽,野草依然
    shiro无法进入授权的方法org.crazycake.shiro.exception.PrincipalInstanceException: class java.util.HashMap must has getter for field: id
    绝望中的希望
    shrio中去掉 login;JSESSIONID
    method 'redisConnectionFactory' threw exception; nested exception is java.lang.NoClassDefFoundError
  • 原文地址:https://www.cnblogs.com/kangchen/p/10750152.html
Copyright © 2011-2022 走看看