线程中的camel http4路由超时

发布于 2024-11-24 09:20:02 字数 380 浏览 0 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寂寞陪衬 2024-12-01 09:20:02

您可以通过指定 http4://foo?httpClient.soTimeout=100 在客户端上设置 100 毫秒超时。当发生超时时,它可能会抛出一个异常,您可以像这样处理(在我的脑海中,未经测试的代码):

onException(IOException.class).to("direct:timeouts");

from("direct:start")
.setHeader(Exchange.HTTP_QUERY,simple("format=json&count=${in.headers.count}"))
.to("http4://www.host.com/someapi?httpClient.soTimeout=100")
.unmarshal().json(JsonLibrary.JACKSON,MyResponseType.class)
.to("bean:SomeBean?method=echo");

from("direct:timeouts").to("...");

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):

onException(IOException.class).to("direct:timeouts");

from("direct:start")
.setHeader(Exchange.HTTP_QUERY,simple("format=json&count=${in.headers.count}"))
.to("http4://www.host.com/someapi?httpClient.soTimeout=100")
.unmarshal().json(JsonLibrary.JACKSON,MyResponseType.class)
.to("bean:SomeBean?method=echo");

from("direct:timeouts").to("...");
花想c 2024-12-01 09:20:02

收件人列表EIP支持超时
http://camel.apache.org/recipient-list.html

The recipient list EIP has timeout support
http://camel.apache.org/recipient-list.html

怎樣才叫好 2024-12-01 09:20:02

更新...我认为超时配置的语法在 Camel 的更高版本中发生了变化。在 Camel 2.16.2 中,我发现文档中的超时参数可以通过查询参数选项设置,但需要以 httpClient. 为前缀。这对我有用:

?httpClient.connectTimeout=10000&httpClient.connectionRequestTimeout=10000&httpClient.socketTimeout=30000

我通过使用小得离谱的值(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:

?httpClient.connectTimeout=10000&httpClient.connectionRequestTimeout=10000&httpClient.socketTimeout=30000

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文