-
Notifications
You must be signed in to change notification settings - Fork 1
/
CommandExecutor.java
36 lines (29 loc) · 1.07 KB
/
CommandExecutor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package HTTPUtils;
import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixThreadPoolKey;
import org.asynchttpclient.DefaultAsyncHttpClient;
import org.asynchttpclient.DefaultAsyncHttpClientConfig;
import org.asynchttpclient.Request;
import org.asynchttpclient.Response;
/**
* Created by deepak.jayaprakash on 15/11/18.
*/
public class CommandExecutor extends HystrixCommand<Response> {
private Request request;
private static DefaultAsyncHttpClient client = new DefaultAsyncHttpClient(new DefaultAsyncHttpClientConfig.Builder()
.setConnectTimeout(10000)
.build());
public CommandExecutor(Request request) {
super(HystrixCommandGroupKey.Factory.asKey("CommandExecutor"));
HystrixThreadPoolKey.Factory.asKey("CommandExecutor");
this.request = request;
}
@Override
protected Response run() throws Exception {
return client.executeRequest(request).get();
}
protected static void closeClient() {
client.close();
}
}