在暴风雨中使用Apache的AsyncHttpClient [英] using Apache's AsyncHttpClient in a storm bolt
问题描述
我有一个螺栓正在为每个元组进行API调用(HTTP Get)。
以避免需要等待响应,我当时想要使用apache HttpAsyncClient。
I have a bolt that is making an API call (HTTP Get) for every tuple. to avoid the need to wait for the response, I was looking to use the apache HttpAsyncClient.
在使用bolt的prepare方法实例化客户端之后,执行方法从元组构造URL并调用sendAsyncGetRequest(url):
after instantiating the client in the bolt's prepare method, the execute method constructs the URL from the tuple and calls sendAsyncGetRequest(url):
private void sendAsyncGetRequest(String url){
httpclient.execute(new HttpGet(url), new FutureCallback<HttpResponse>() {
@Override
public void completed(HttpResponse response) {
LOG.info("Response Code : " + response.getStatusLine());
LOG.debug(response.toString());
}
@Override
public void failed(Exception ex) {
LOG.warn("Async http request failed!", ex);
}
@Override
public void cancelled() {
LOG.warn("Async http request canceled!");
}
});
}
拓扑部署但Storm UI显示错误:
the topology deploys but the Storm UI shows an error:
java.lang.RuntimeException: java.lang.IllegalStateException: Request cannot be executed; I/O reactor status: STOPPED at backtype.storm.utils.DisruptorQueue.consumeBatchToCursor(DisruptorQueue.java:12
推荐答案
您是否在回调可以执行之前关闭主流中的客户端(client.close();)?
Are you shutting down the client (client.close();) in your main flow before the callback can execute?
错误是说IO路径已经关闭。通常,异步客户端的实例应该重复用于重复请求,并且仅在发出ALL请求时销毁,例如在应用程序关闭时。
The error is saying that the IO path has already been closed. In general, instances of async clients should be re-used for repeated requests and destroyed only when "ALL" requests have been made, e.g. at application shutdown.
这篇关于在暴风雨中使用Apache的AsyncHttpClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!