package com.cpop.core.config;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

/**
 * @author DB
 * @version 1.0.0
 * @since 2023-12-08 16:35
 */
@Configuration
public class RestTemplateConfig {

    @Bean
    public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) {
        // 设置连接超时时间为 5 秒
        restTemplateBuilder.setConnectTimeout(Duration.ofMillis(5000));
        // 设置读取超时时间为 10 秒
        restTemplateBuilder.setReadTimeout(Duration.ofMillis(10000));
        // 使用 HttpComponentsClientHttpRequestFactory 客户端请求工厂实例创建 RestTemplate 实例
        return restTemplateBuilder.build();
    }

}
