Commit 4eb0f339 by Amir Aharon

2.1.2 - add config for ok-http client read/connect timeouts:

"microservice.http.client.read.timeout.seconds" (30)
"microservice.http.client.connect.timeout.seconds" (10)
parent 48628c91
group 'com.ipgallery.common' group 'com.ipgallery.common'
version '2.1.1' version '2.1.2'
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
......
...@@ -47,6 +47,7 @@ import java.util.ArrayList; ...@@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
...@@ -58,10 +59,11 @@ import static microservice.io.iface.IRestClient.COMMAND_ERROR; ...@@ -58,10 +59,11 @@ import static microservice.io.iface.IRestClient.COMMAND_ERROR;
*/ */
public class RestHttpClient extends SimpleRestClient implements Closeable { public class RestHttpClient extends SimpleRestClient implements Closeable {
private final int HTTP_SOCKET_READ_TIMEOUT = Integer.valueOf(System.getProperty("microservice.http.client.read.timeout.seconds","30"));
private final int HTTP_SOCKET_CONNECT_TIMEOUT = Integer.valueOf(System.getProperty("microservice.http.client.connect.timeout.seconds","10"));
List<String> brrFieldNames = null; List<String> brrFieldNames = null;
// CloseableHttpAsyncClient httpAsyncClient = null; // CloseableHttpAsyncClient httpAsyncClient = null;
String scheme = Constants.HTTP_SCHEME; // default scheme String scheme = Constants.HTTP_SCHEME; // default scheme
public RestHttpClient(String app, String ip, int port) { public RestHttpClient(String app, String ip, int port) {
...@@ -85,9 +87,11 @@ public class RestHttpClient extends SimpleRestClient implements Closeable { ...@@ -85,9 +87,11 @@ public class RestHttpClient extends SimpleRestClient implements Closeable {
} }
private void initClient() { private void initClient() {
client = new OkHttpClient(); client = new OkHttpClient.Builder()
// httpAsyncClient = createHttpClient(); .connectTimeout(HTTP_SOCKET_CONNECT_TIMEOUT, TimeUnit.SECONDS)
// httpAsyncClient.start(); .writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(HTTP_SOCKET_READ_TIMEOUT, TimeUnit.SECONDS)
.build();
initBaseRestValidation(); initBaseRestValidation();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment