3.14. 配置 AsyncHttpClient
AsyncHttpClient
客户端使用 AsyncHttpClientConfig
来配置客户端。如需了解更多详细信息,请参阅
Async Http Client 的文档。
在 Camel 2.8 中,配置仅限于使用 AsyncHttpClientConfig.Builder
提供的构建器模式。在 Camel 2.8 中,Async
HttpClientConfig 不支持 getters/setters,因此无法使用 Spring bean 风格(如 XML 文件中的 <bean> 标签)轻松创建/配置。
以下示例演示了如何使用构建器来创建 AsyncHttpClientConfig
,它配置在 AhcComponent
。
在 Camel 2.9 中,AHC 组件使用 Async HTTP 库 1.6.4。这个更新的版本添加了对普通 bean 风格配置的支持。AsyncHttpClientConfigBean
类为 AsyncHttpClientConfig
中可用的配置选项提供 getters 和 setters。AsyncHttpClientConfigBean
实例可以直接传递给 AHC 组件,或使用 clientConfig
URI 参数在端点 URI 中引用。
Camel 2.9 也可以在 URI 中直接设置配置选项。以 "clientConfig." 开头的 URI 参数可用于设置 AsyncHttpClientConfig
的各种可配置属性。端点 URI 中指定的属性与 "clientConfig" URI 参数引用的配置中指定的属性与使用 "clientConfig." 参数具有优先级设置的配置合并。引用的 AsyncHttpClientConfig
实例始终为每个端点复制,这样一个端点上的设置将独立于之前创建的任何端点的设置。以下示例演示了如何使用 "clientConfig." 类型 URI 参数配置 AHC 组件。
from("direct:start") .to("ahc:http://localhost:8080/foo?clientConfig.maxRequestRetry=3&clientConfig.followRedirects=true")