我不熟悉apache骆驼。我的项目是用骆驼xml文件编写的。
我有一个要求,例如从文件中获取数据,首先通过调用GET api来检查数据是否在DB中可用,如果数据在那里,则对数据进行一些更改,然后再次调用PUT api来更新数据。如果没有数据,则只需调用PUT api即可创建新记录。
下面是代码已经存在,我尝试做一些事情
eqosRoutes.xml
select *
from the_table
where properties @@ '$.*.*.c == "some value"'
TradingPartnerRoutes.xml
<routeContext id="eqosRoutes" xmlns="http://camel.apache.org/schema/spring">
<route id="eqosSupplierFilePollerRoute">
<from
uri="file://{{eqos.feed.polling.directory}}?fileName={{eqos.feed.supplier.file.name}}&doneFileName={{eqos.feed.supplier.trigger.file.name}}&move=.done&moveFailed=.error&delay={{eqos.feed.polling.interval}}&charset={{eqos.feed.character.encoding}}" />
<log
message="EQOS Supplier Feed Poller Route Received a File for processing.."
loggingLevel="INFO" />
<enrich uri="direct:setUserTokenCache" strategyRef="aggregationStrategy" />
<to uri="direct:processEQOSSupplier" />
</route>
<route id="eqosSupplierProcessRoute1">
<from uri="direct:processEQOSSupplier"/>
<log loggingLevel="INFO" message="EQOS Supplier Feed Processing Started" />
<split streaming="true" parallelProcessing="false">
<ref>staxRecordEQOSSupplier</ref>
<log loggingLevel="INFO"
message="EQOS Supplier Feed Processing Started ${body}" />
<choice>
<when>
<simple>${body.supplierId} != null</simple>
<transform>
<method bean="EQOSTransformer" method="transformSupplier" />
</transform>
<doTry>
<to uri="direct:invokegetPartnerAPI" />
<doCatch>
<exception>com.hello.tpil.common.exception.AuthenticationException</exception>
<handled>
<constant>false</constant>
</handled>
<log loggingLevel="WARN"
message="invokegetPartnerAPI - AuthenticationException..Retrying for.. ${body}" />
<to uri="direct:setUserTokenCache" />
</doCatch>
<doCatch>
<exception>java.lang.Exception</exception>
<handled>
<constant>false</constant>
</handled>
<log loggingLevel="ERROR"
message="invokegetPartnerAPI - Error invoking API - ${body}" />
<log loggingLevel="ERROR"
message="invokegetPartnerAPI - Exception StackTrace - ${exception}" />
</doCatch>
</doTry>
</when>
<otherwise>
<log loggingLevel="INFO"
message="Not a valid body as supplier ID missing..so ignoring for supplier name ${body.partnerName}" />
</otherwise>
</choice>
</split>
<log message="EQOS Supplier Feed Processing Completed."
loggingLevel="INFO" />
</route>
<route id="eqosSupplierProcessRoute">
<from uri="direct:processEQOSSupplier" />
<log loggingLevel="INFO" message="EQOS Supplier Feed Processing Started" />
<split streaming="true" parallelProcessing="false">
<ref>staxRecordEQOSSupplier</ref>
<log loggingLevel="INFO"
message="EQOS Supplier Feed Processing Started ${body}" />
<choice>
<when>
<simple>${body.supplierId} != null</simple>
<transform>
<method bean="EQOSTransformer" method="transformSupplier" />
</transform>
<doTry>
<to uri="direct:invokeCreateOrReplacePartnerAPI" />
<doCatch>
<exception>com.hello.tpil.common.exception.AuthenticationException</exception>
<handled>
<constant>false</constant>
</handled>
<log loggingLevel="WARN"
message="invokeCreateOrReplacePartnerAPI - AuthenticationException..Retrying for.. ${body}" />
<to uri="direct:setUserTokenCache" />
</doCatch>
<doCatch>
<exception>java.lang.Exception</exception>
<handled>
<constant>false</constant>
</handled>
<log loggingLevel="ERROR"
message="invokeCreateOrReplacePartnerAPI - Error invoking API - ${body}" />
<log loggingLevel="ERROR"
message="invokeCreateOrReplacePartnerAPI - Exception StackTrace - ${exception}" />
</doCatch>
</doTry>
</when>
<otherwise>
<log loggingLevel="INFO"
message="Not a valid body as supplier ID missing..so ignoring for supplier name ${body.partnerName}" />
</otherwise>
</choice>
</split>
<log message="EQOS Supplier Feed Processing Completed."
loggingLevel="INFO" />
</route>
</routeContext>
我可以调用GET API来检查数据是否存在。但是之后,我必须将数据传递给createOrReplacePartnerAPI,以调用PUT api进行更新。
同样,除了检查数据的可用性外,我不希望GET api响应。
我面临的另一个问题是,我需要suplierId被动态添加到GET URL的URI中,但我无法做到这一点。
答案 0 :(得分:0)
请在下面找到我的评论:
我可以调用GET API来检查数据是否存在。但是之后,我必须将数据传递给createOrReplacePartnerAPI,以调用PUT api进行更新。
[Ankit]:调用get api时,交换正文将替换为响应,并且文件中的数据也将替换。如果要在收到get API响应后获取文件(拆分数据),则需要在发送get调用请求之前将主体存储到交换属性中,并且可以在get api调用之后进行检索。
同样,我不想要GET api响应,而不仅仅是检查数据的可用性。 [Ankit]:您可以将get响应正文替换为您在上述步骤中设置的原始文件数据。
我面临的另一个问题是,我需要suplierId才能动态地将其添加到GET URL的URI中,但我无法做到这一点。 [Ankit]:您应该创建cxfrs端点并像下面这样动态设置http路径
width:100%