I use Spring Boot and created a service (part of Microservices Design). I have the below method,
public static HttpClient getHttpClient() throws KeyManagementException, NoSuchAlgorithmException {
log.info("Creating Http Client...");
final SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().build());
final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(200);
connectionManager.setDefaultMaxPerRoute(20);
return HttpClients.custom()
.disableRedirectHandling()
.setSSLSocketFactory(sslConnectionSocketFactory)
.setConnectionManager(connectionManager)
.build();
}
I invoke this method multiple times, wanted to maintain only one instance and reuse it once created. Considering concurrent programming, can i use Singleton Pattern? and i see RestTemplate is pretty good approach rather than Apache Http Client as per below link,
RestTemplate vs Apache Http Client for production code in spring project
Suggestion are much appreciated.
Aucun commentaire:
Enregistrer un commentaire