我是Apache Camel的新手。我已经将我的应用程序设置为使用基于XML配置的Apache Camel。我的配置包含多个具有相似步骤的路线。我试图找到一种方法来将这些不同路线的共同或重复部分放置在一个地方,并将它们从路线中引用而不是一次又一次地重复它们?如何写简洁的apache骆驼xml
例如,在我下面的骆驼路线配置中,路线2重复了路线1的几个步骤。那么是否有办法提取路线1和路线2的常见步骤,然后参考路线1和2中提取的部分?
<context:property-placeholder location="classpath:quartz.properties" />
<context:component-scan base-package="com"></context:component-scan>
<camel:route>
<camel:from uri="quartz://deadlines/SDGWD?cron=15+34+14+?+*+MON-SUN+*" />
<camel:onCompletion>
<camel:to uri="seda:checkAnyPendingDeadlines"/>
</camel:onCompletion>
<camel:to uri="bean:sdgwdNotifier" />
<camel:choice>
<camel:when>
<camel:method ref="deadlineHandler" method="canProcessDeadline" />
<camel:bean ref="deadlineHandler" method="prepareDeadline" />
<camel:bean ref="sdgwdProcessor" method="initiateMessageProcessing" />
<camel:bean ref="schedulerXdrTransformer" method="marshall" />
<camel:to uri="wmq:SU.SES" />
<camel:bean ref="sdgwdProcessor" method="waitForAcknowledgment" />
<camel:bean ref="sdgwdProcessor" method="afterMessageProcessed" />
<camel:bean ref="deadlineHandler" method="onDeadlineProcessingCompletion" />
</camel:when>
<camel:otherwise>
<camel:bean ref="deadlineHandler" method="enqueDeadline" />
</camel:otherwise>
</camel:choice>
</camel:route>
<camel:route>
<camel:from uri ="seda:checkAnyPendingDeadlines"/>
<camel:onCompletion>
<camel:to uri ="seda:checkAnyPendingDeadlines"/>
</camel:onCompletion>
<camel:to uri="bean:deadlineHandler?method=getNextProcessableDeadline" />
<camel:choice>
<camel:when>
<camel:method ref="deadlineHandler" method="canProcessDeadline" />
<camel:bean ref="deadlineHandler" method="prepareDeadline" />
<camel:choice>
<camel:when>
<camel:simple>${body.deadline} == ${type:settlementcontrol.scheduler.model.Deadline.SDGW} </camel:simple>
<camel:bean ref="sdgwdProcessor" method="initiateMessageProcessing" />
<camel:bean ref="schedulerXdrTransformer" method="marshall" />
<camel:to uri="wmq:SU.SES" />
<camel:bean ref="sdgwdProcessor" method="waitForAcknowledgment" />
<camel:bean ref="sdgwdProcessor" method="afterMessageProcessed" />
<camel:bean ref="deadlineHandler" method="onDeadlineProcessingCompletion" />
</camel:when>
</camel:choice>
</camel:when>
<camel:otherwise>
<camel:bean ref="deadlineHandler" method="enqueDeadline" />
</camel:otherwise>
</camel:choice>
</camel:route>
感谢, Vaibhav的
谢谢@罗伯特。我已经使用直接组件提取出了通用部分。但是,我仍然希望避免重复的子路线上还有很少的步骤。 Apache骆驼文档称AOP已被弃用。那么有没有更好的方法来围绕建议实现AOP? – Vaibhav
你能解释为什么这些步骤不能成为普通流程的一部分(或举例),让我更好地把握这个问题? –