178.16. 关于生存时间
先阅读以上有关同步时钟的上方。
当您通过 Camel 与 JMS 进行请求/恢复(InOut)时,Camel 在发送方一侧使用超时,这是来自 requestTimeout
选项中的 20 秒。您可以通过设置 higher/lower 值来控制这一点。但是,在 JMS 消息上仍设置时间为 live 值。要求在系统间同步时钟。如果没有,您可能要禁用要设置的实时值。现在,可以使用 Camel 2.8 的 disableTimeToLive
选项。因此,如果您将此选项设置为 disableTimeToLive=true
,则 Camel 在发送 JMS 消息时不会将任何时间设置为 live 值。但是,请求超时仍然活跃。因此,如果您对 JMS 进行请求/恢复并禁用了生存时间,则 Camel 仍将使用 20 秒超时( requestTimeout
选项)。该选项也可以配置。因此,两个选项 requestTimeout
和 disableTimeToLive
为您提供对请求/给予给予的细粒度控制。
从 Camel 2.13/2.12.3 开始,您可以在消息中提供标头来覆盖并使用 作为请求超时值,而不是端点配置的值。例如:
from("direct:someWhere") .to("jms:queue:foo?replyTo=bar&requestTimeout=30s") .to("bean:processReply");
from("direct:someWhere")
.to("jms:queue:foo?replyTo=bar&requestTimeout=30s")
.to("bean:processReply");
在上面的路由中,我们有一个端点配置的 requestTimeout
为 30 秒。因此,Camel 将等待 30 秒,以便该回复消息回到 bar 队列上。如果未收到回复消息,则 Exchange 和 Camel 设置了 org.apache.camel.ExchangeTimedOutException
,然后因为例外情况而失败,Camel 错误处理程序才会响应。
如果要使用每条消息超时值,则可以使用键 org.apache.camel.component.jms.JmsConstants#JMS_REQUEST_TIMEOUT
s#JMS_REQUEST_TIMEOUT 设置标头,其值为 "CamelJmsRequestTimeout"
,其超时值为长类型。
例如,我们可以使用 bean 计算每个单个消息的超时值,例如在 service bean 上调用 "whatIs TheTimeout"
方法,如下所示:
from("direct:someWhere") .setHeader("CamelJmsRequestTimeout", method(ServiceBean.class, "whatIsTheTimeout")) .to("jms:queue:foo?replyTo=bar&requestTimeout=30s") .to("bean:processReply");
from("direct:someWhere")
.setHeader("CamelJmsRequestTimeout", method(ServiceBean.class, "whatIsTheTimeout"))
.to("jms:queue:foo?replyTo=bar&requestTimeout=30s")
.to("bean:processReply");
当您用 Camel 相对 JMS 触发和忘记(InOut)时,Camel 默认 不会在 消息上将任何时间设置为实时值。您可以使用 timeToLive
选项配置值。例如,要指示 5 sec。设置 timeToLive=5000
。可以使用 option disableTimeToLive
选项,强制禁用时间为 live,也用于 InOnly messaging。requestTimeout
选项不用于 InOnly 消息传递。