Apache camel Camel中的递归调用
我有一个带有Camel的项目,我的路由本身有一个递归调用,以便实现逻辑“在返回数据集时调用存储过程”:Apache camel Camel中的递归调用,apache-camel,Apache Camel,我有一个带有Camel的项目,我的路由本身有一个递归调用,以便实现逻辑“在返回数据集时调用存储过程”: ${body}!=无效的 ${body.transactions} 这段代码的问题是,如果我的存储过程长时间不允许退出递归而不断返回某些内容,那么我会得到java.lang.StackOverflowerError。我需要像loop这样的东西。用Camel实现这种逻辑的最佳方法是什么?我使用的是Camel 2.15.3。我找到了一个具有自定义bean和循环退出条件的变通方法(isLoopD
${body}!=无效的
${body.transactions}
这段代码的问题是,如果我的存储过程长时间不允许退出递归而不断返回某些内容,那么我会得到
java.lang.StackOverflowerError
。我需要像loop这样的东西。用Camel实现这种逻辑的最佳方法是什么?我使用的是Camel 2.15.3。我找到了一个具有自定义bean和循环退出条件的变通方法(isLoopDone
属性)
直接:CallStoredPocwhileithatransactions
${body}!=无效的
${body.transactions}
真的
也许可以异步转到
?我需要类似于loop的东西。
例如,Bedla提到Hanks时有loop EIp,但我不能使用loop EIp,因为我没有预定义的迭代次数,“loopDoWhile”在Camel 2.15.3中不存在。
<route id="trxnReader">
<from uri="direct:query"/>
<to uri="sql-stored:classpath:sql/getTrxnsProcedure.sql?dataSource=myDataSource"
id="storedprocGetTrxns"/>
<choice>
<when>
<simple>${body} != null</simple>
<split>
<simple>${body.transactions}</simple>
<filter>
<method ref="trnxFilter" method="filter"/>
<to uri="direct:processTrxn"/>
</filter>
</split>
<to uri="direct:query"/>
</when>
<otherwise>
<log id="failUploadInfo" message="Transactions don't exist" loggingLevel="INFO"/>
</otherwise>
</choice>
</route>
public class LoopBean {
@Handler
public void loop(@ExchangeProperty("loopEndpoint") String endpoint, Exchange exchange) {
ProducerTemplate producerTemplate = exchange.getContext().createProducerTemplate();
boolean isLoopDone = false;
Exchange currentExchange = exchange;
do {
currentExchange = producerTemplate.send(endpoint, currentExchange);
Object isLoopDoneProperty = currentExchange.getProperty("isLoopDone");
if (isLoopDoneProperty != null) {
isLoopDone = (boolean) isLoopDoneProperty;
}
}
while (!isLoopDone);
}
}
<route id="trxnReader">
<from uri="direct:query"/>
<setProperty propertyName="loopEndpoint">
<simple>direct:callStoredProcWhileItHasTransactions</simple>
</setProperty>
<bean ref="loopBean"/>
</route>
<route id="storedProcCallingLoop">
<from uri="direct:callStoredProcWhileItHasTransactions"/>
<to uri="sql-stored:classpath:sql/getTrxnsProcedure.sql?dataSource=myDataSource"
id="storedprocGetTrxns"/>
<choice>
<when>
<simple>${body} != null</simple>
<split>
<simple>${body.transactions}</simple>
<filter>
<method ref="trnxFilter" method="filter"/>
<to uri="direct:processTrxn"/>
</filter>
</split>
</when>
<otherwise>
<log id="failUploadInfo" message="Transactions don't exist" loggingLevel="INFO"/>
<setProperty propertyName="isLoopDone">
<simple resultType="java.lang.Boolean">true</simple>
</setProperty>
</otherwise>
</choice>
</route>