package com.lincfusion.udyamlinc.config; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.web.client.RestClient; import java.time.Duration; /** * The HTTP client used for external feeds, and the scheduler that drives them. * *
Short, explicit timeouts are the point: a government endpoint that hangs * must fail the nightly job quickly, not hold a thread until someone notices. * Nothing in the request path uses this client — see ARCHITECTURE §2.1. */ @Configuration @EnableScheduling public class ExternalFeedConfig { @Value("${udyam.ingestion.http.connect-timeout-ms:10000}") private int connectTimeoutMs; @Value("${udyam.ingestion.http.read-timeout-ms:30000}") private int readTimeoutMs; /** * Built from {@link RestClient#builder()} rather than an injected * auto-configured {@code RestClient.Builder}, which Boot does not always * expose as a bean. It also keeps this client free of any global customiser * meant for the request path — the feed client's timeouts are deliberately * its own. */ @Bean("externalFeedClient") public RestClient externalFeedClient() { SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setConnectTimeout(Duration.ofMillis(connectTimeoutMs)); factory.setReadTimeout(Duration.ofMillis(readTimeoutMs)); return RestClient.builder().requestFactory(factory).build(); } }