【问题标题】:Http Connection Pooling in CamelCamel 中的 Http 连接池
【发布时间】:2017-04-02 04:29:15
【问题描述】:

我使用 Camel 作为编排引擎。

clients sends HTTP request <-> CAMEL code <---- HTTP Req----- > external
server(s)

我正在使用 HTTP4 组件(使用默认设置)发出 HTTP 请求 到外部服务器。我有很多 http 后端。

现在我们对后端进行 http 调用的方式如下:-

// The producer is created during app initialisation. This is actually done
via blueprint.xml
ProducerTemplate producer = camelContext.createProducerTemplate();

// Whenever I need to make a http call I am executing the below code with
URL set as something like:- "http4://order-api:8099/orders/v1/ordersearch/"

Exchange exchange = producer.request(URL, new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
        log.info("Executing the HTTP request : URL - " + URL + " Headers -
" + headers + " Body : " + body);
        exchange.getIn().setHeaders(headers);
        exchange.getIn().setBody(body);
        }
    });

我的查询是:-

  1. HTTP4 在默认设置中是否使用了一些 http 连接 在调用外部服务器时进行池化?
  2. 如果是的话有没有办法可以配置连接池 blueprint.xml?

我正在使用Camel 2.16.1,应用程序部署在Karaf 3.0.5

【问题讨论】:

    标签: apache-camel


    【解决方案1】:

    http4 组件使用 Apache HttpClient,它支持使用 HttpClientConnectionManager 进行池化。

    默认情况下,camel 使用PoolingHttpClientConnectionManager,它配置有connectionsPerRoutemaxTotalConnections 属性。

    如果你想对这个clientConnectionManager有更多的控制,你可以提供你自己的org.apache.http.conn.HttpClientConnectionManager实现

    HttpClient connection manager

    【讨论】:

    • 根据 camel.apache.org/… connectionsPerRoutemaxTotalConnections 的默认值是 20 和 200。你能告诉我这两者有什么区别吗?假设我有 3 个 http 后端 A,BC。那么每个人都有一个最大的 20 个连接池,总计 60 个?如果是,如果我有超过 200 个 http 后端怎么办?
    • 您应该查看 Apache HttpClient 文档。 maxTotalConnections 是池管理的连接总数。在connectionsPerRoute 中,路由与骆驼无关,而是与HttpRoute 相关,HttpRoute 是“目的地”(主机 + 端口 + 代理/隧道)。所以你是对的:默认情况下,哪 3 个“目的地”最多打开 60 个连接。您当然可以更改此默认配置
    猜你喜欢
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 1970-01-01
    • 2017-07-15
    • 2011-06-18
    • 2016-07-09
    相关资源
    最近更新 更多