package shop.alien.job.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @author ssk
 * @version 1.0
 * @date 2022/7/11 14:35
 */
@Configuration
public class Config {

    //单位为ms
    private static final Integer READ_TIME_OUT = 50000;
    private static final Integer CONNECTION_TIME_OUT = 50000;

    /**
     * restTemplate用于发送post请求
     *
     * @param factory 客户请求工厂
     * @return RestTemplate
     */
    @Bean
    public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
        return new RestTemplate(factory);
    }

    @Bean
    public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setReadTimeout(READ_TIME_OUT);
        factory.setConnectTimeout(CONNECTION_TIME_OUT);
        return factory;
    }
}
