Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何停止骆驼http重试_Java_Apache Camel_Apache Httpcomponents - Fatal编程技术网

Java 如何停止骆驼http重试

Java 如何停止骆驼http重试,java,apache-camel,apache-httpcomponents,Java,Apache Camel,Apache Httpcomponents,我们正在使用camel 2.18.1的toD组件向http web服务发布正文,但当url无效时,camel会在内部重试2-3分钟,这是我不希望看到的 我进一步研究发现,camel在内部使用org.apache.commons.httpclient.HttpMethodDirector执行重试操作。如何才能阻止骆驼这样做 零件异常日志如下所示 <2017-03-29 16:33:59,084>:<>:<>:<>:<org.apache.com

我们正在使用camel 2.18.1的toD组件向http web服务发布正文,但当url无效时,camel会在内部重试2-3分钟,这是我不希望看到的

我进一步研究发现,camel在内部使用
org.apache.commons.httpclient.HttpMethodDirector
执行重试操作。如何才能阻止骆驼这样做

零件异常日志如下所示

<2017-03-29 16:33:59,084>:<>:<>:<>:<org.apache.commons.httpclient.HttpMethodDirector>:<INFO >:[Camel (camel-1) thread #20 - Threads]::<I/O exception (java.net.ConnectException) caught when processing request: Connection timed out (Connection timed out)>
<2017-03-29 16:33:59,085>:<>:<>:<>:<org.apache.commons.httpclient.HttpMethodDirector>:<INFO >:[Camel (camel-1) thread #20 - Threads]::<Retrying request>
<2017-03-29 16:36:06,313>:<>:<>:<>:<org.apache.commons.httpclient.HttpMethodDirector>:<INFO >:[Camel (camel-1) thread #20 - Threads]::<I/O exception (java.net.ConnectException) caught when processing request: Connection timed out (Connection timed out)>
<2017-03-29 16:36:06,314>:<>:<>:<>:<org.apache.commons.httpclient.HttpMethodDirector>:<INFO >:[Camel (camel-1) thread #20 - Threads]::<Retrying request>
<2017-03-29 16:38:13,545>:<>:<>:<>:<org.apache.commons.httpclient.HttpMethodDirector>:<INFO >:[Camel (camel-1) thread #20 - Threads]::<I/O exception (java.net.ConnectException) caught when processing request: Connection timed out (Connection timed out)>
<2017-03-29 16:38:13,546>:<>:<>:<>:<org.apache.commons.httpclient.HttpMethodDirector>:<INFO >:[Camel (camel-1) thread #20 - Threads]::<Retrying request>

实现HttpClientConfigurer并将其发送到注册表

@Bean(name = "httpConfigurer")
public HttpClientConfigurer createCustomConfigurer() {
    return new HttpClientConfigurer() {

        @Override
        public void configureHttpClient(HttpClient client) {
            client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000);
            client.getParams().setParameter("http.method.retry-handler", new DefaultHttpMethodRetryHandler(0, false));            }
    };
}
设置HttpComponent的
httpClientConfigurer
,如下所示:

.toD("http://1.2.3.4/xyz?httpClientConfigurer=httpConfigurer")

每当我们使用无效URL并试图发布消息时,线程都会等待2分钟以上,直到超时。因此,其他线程会被卡住。那么,我可以将camel route builder的连接超时配置为10秒吗?您在这里提到的示例是使用“to”组件,但我们使用的是routebuilder中的“toD”(使用java DSL)。添加
client.getParams().setParameter(HttpConnectionParams.connection\u TIMEOUT,10000)
配置HttpClient
,正如您在我的更新答案中所看到的。您是否尝试过用类似
OneException(ConnectException.class).handled(true).maximumRedeliveries(0)?在这里,你明确地说,不应尝试重新交付。@RomanVottner我面临着同样的问题。我尝试了这个解决方案,但它没有从
maximumRedeliveries
方法中选择重试次数,也没有覆盖它。在我看来,它似乎是由
org.apache.commons.httpclient.HttpMethodDirector
类驱动的
@Bean(name = "httpConfigurer")
public HttpClientConfigurer createCustomConfigurer() {
    return new HttpClientConfigurer() {

        @Override
        public void configureHttpClient(HttpClient client) {
            client.getParams().setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 10000);
            client.getParams().setParameter("http.method.retry-handler", new DefaultHttpMethodRetryHandler(0, false));            }
    };
}
.toD("http://1.2.3.4/xyz?httpClientConfigurer=httpConfigurer")