2014-01-06 172 views
0

我是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的

回答

1

是常见的途径,其中包含重复的流程的一部分,是否足够?如果是这样,那么创建这样的事情:

<camel:route id="myCommonPartOfFlow"> 
    <camel:from uri="direct-vm:common-in"/> 
    [common part] 
</camel:route> 

您可以从您的主要路线,如今调用你的子(myCommonPartOfFlow)路线:

<camel:to uri="direct-vm:common-in/> 
+0

谢谢@罗伯特。我已经使用直接组件提取出了通用部分。但是,我仍然希望避免重复的子路线上还有很少的步骤。 Apache骆驼文档称AOP已被弃用。那么有没有更好的方法来围绕建议实现AOP? – Vaibhav

+0

你能解释为什么这些步骤不能成为普通流程的一部分(或举例),让我更好地把握这个问题? –

0

您可以使用一个direct组件来创建子路径这一因素通用部分或拆分路由,以便公共路由拥有自己的路由,然后其他路由可以将消息发送到公共路由。例如,如果您有两条路线执行以下过程“过程A” - >“过程B” - >“过程C”和“过程D” - >“过程B” - >“过程E”,则可以分离将B处理成它自己的路由并执行以下操作:

from(“jms:queue:processB”) - “Process C” - > end() 进程A - >设置Header“JMSReplyTo”,jms:queue: processC - >到(“jms:queue:processB”) 进程C - >设置Header“JMSReplyTo”,jms:queue:processE - >到(“jms:queue:processB”)

为了简洁我使用Java DSL,但使用XML DSL也可以做到这一点。我还使用“过程A”等来抽象可能是路线中的多个步骤。无论过程是什么,连接路线的概念都是一样的。这种方法的好处是它允许“流程B”的联合来处理额外的负载并在您的基础设施周围分配处理。一旦你进入Asynchrounous编程,你的能力会提高很多。