关闭骆驼路线耗费时间

时间:2013-11-05 11:58:21

标签: apache-camel shutdown

我们有一个查看文件并在此文件上处理可能数百条记录的camel路由,几乎就像批处理例程(但在camel中只有一条消息)。因此,该消息可能需要几分钟或几小时才能完成。我们希望在此消息(以及其他任何其他等待)完成后关闭队列。

我们需要考虑以下因素:

关闭策略定义在强制关闭之前等待路由停止的时间

<bean id="shutdown" class="org.apache.camel.impl.DefaultShutdownStrategy"> 
 <property name="timeout" value="#[bpf.defaultShutdownStrategy.timeout]"/>
</bean>

该路由有一个参数shutdownRunningTask =“CompleteAllTask​​s”,它应该等待直到处理完所有消息。     

不确定哪个会占用总统,因为超时超时不是优雅,它会强制关机,对于我们的scneario,我们可能会超过超时,因为我们无法预测处理需要多长时间。

任何想法/考虑因素? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

您应该查看onCompletion功能。它在Exchange完成时在分离的线程中添加新路由。

以下是Camel文档中的一些示例:

Java DSL

// define a global on completion that is invoked when the exchange is complete
onCompletion().to("log:global").to("mock:sync");

from("direct:start")
    .process(new MyProcessor())
    .to("mock:result");

XML DSL

<!-- this is a global onCompletion route that is invoke when any exchange is complete
     as a kind of after callback -->
<onCompletion>
    <to uri="log:global"/>
    <to uri="mock:sync"/>
</onCompletion>

<route>
    <from uri="direct:start"/>
    <process ref="myProcessor"/>
    <to uri="mock:result"/>
</route>

然后,这里有documentation 如何在Camel中停止路线

相关问题