线程中的camel http4路由超时
我想使用 http4 路由,但让它在超时的线程内执行。我已经有了 http4 路由设置,如下所示:
from("direct:start")
.setHeader(Exchange.HTTP_QUERY,simple("format=json&count=${in.headers.count}"))
.to("http4://www.host.com/someapi")
.unmarshal().json(JsonLibrary.JACKSON,MyResponseType.class)
.to("bean:SomeBean?method=echo");
我想在 http 调用周围应用 100 毫秒超时,并在这种情况下路由到失败处理程序。有谁知道如何做到这一点?
I'd like to use http4 route, but have it execute inside a thread with a timeout. I already have my http4 route setup, something like this:
from("direct:start")
.setHeader(Exchange.HTTP_QUERY,simple("format=json&count=${in.headers.count}"))
.to("http4://www.host.com/someapi")
.unmarshal().json(JsonLibrary.JACKSON,MyResponseType.class)
.to("bean:SomeBean?method=echo");
I'd like to apply a 100ms timeout around the http call, and route to a failure handler in that case. Does anyone know how that can be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过指定
http4://foo?httpClient.soTimeout=100
在客户端上设置 100 毫秒超时。当发生超时时,它可能会抛出一个异常,您可以像这样处理(在我的脑海中,未经测试的代码):You can set a 100ms timeout on the client by specifying
http4://foo?httpClient.soTimeout=100
. When a timeout occurs it will probably throw an exception that you can handle like so (off the top of my head, untested code):收件人列表EIP支持超时
http://camel.apache.org/recipient-list.html
The recipient list EIP has timeout support
http://camel.apache.org/recipient-list.html
更新...我认为超时配置的语法在 Camel 的更高版本中发生了变化。在 Camel 2.16.2 中,我发现文档中的超时参数可以通过查询参数选项设置,但需要以 httpClient. 为前缀。这对我有用:
我通过使用小得离谱的值(1毫秒)进行测试进行了验证,它产生了“读取超时”错误。
看起来 httpClient 的可用选项是 RequestConfig.Builder。
An update... I think the syntax for the timeout configurations has changed in later versions of Camel. With Camel 2.16.2 I found that the timeout parameters in the documentation can be set via query param options, but they need to be prefixed with httpClient. . Here is what worked for me:
I verified by testing with ridiculously small values (1 ms) and it produced "read timed out" errors.
It looks the availble options for httpClient are the setter values on RequestConfig.Builder.