Apache camel 如何编写简明的apachecamel-xml

Apache camel 如何编写简明的apachecamel-xml,apache-camel,Apache Camel,我是新来的阿帕奇骆驼。我已经使用基于XML的配置将我的应用程序设置为使用ApacheCamel。我的配置包含多个具有类似步骤集的路由。我想知道是否有办法将这些不同路线的公共或重复部分放在一个地方,并从路线中引用它们,而不是一次又一次地重复它们 例如,在我下面的驼峰路线配置中,路线2重复路线1的几个步骤。那么,有没有办法提取路线1和路线2的常见步骤,然后参考路线1和路线2中提取的部分 <context:property-placeholder location="classpath:quar

我是新来的阿帕奇骆驼。我已经使用基于XML的配置将我的应用程序设置为使用ApacheCamel。我的配置包含多个具有类似步骤集的路由。我想知道是否有办法将这些不同路线的公共或重复部分放在一个地方,并从路线中引用它们,而不是一次又一次地重复它们

例如,在我下面的驼峰路线配置中,路线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>

${body.deadline}==${type:settlementcontrol.scheduler.model.deadline.SDGW}

谢谢,
Vaibhav是一条普通路线,它包含你的流程的重复部分,足够吗?如果是这样,那么创建如下内容:

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

[共同部分]
现在,您可以从主路线调用子(MyCommonPartOffflow)路线:

<camel:to uri="direct-vm:common-in/>
您可以使用一个组件创建子例程来分解公共部分,也可以拆分路由,使公共路由有自己的路由,然后其他路由可以向公共路由发送消息。例如,如果有两个路由执行以下流程“流程A”->“流程B”->“流程C”和“流程D”->“流程B”->“流程E”,则可以将流程B拆分为自己的路由并执行以下操作:

from(“jms:queue:processB”)-“processc”->end() 流程A->将标题“JMSReplyTo”,jms:queue:processC->设置为(“jms:queue:processB”) 进程C->设置头“JMSReplyTo”,jms:queue:processE->to(“jms:queue:processB”)


为了简洁起见,我使用了JavaDSL,但同样可以使用XMLDSL。我还使用了“流程A”之类的方法来抽象路线中的多个步骤。无论流程是什么,链接路线的概念都是相同的。这种方法的优点是,它允许“进程B”的联合来处理额外的负载,并在您的基础结构周围分布处理。一旦你使用异步编程,你的能力就会大大提高。

谢谢@Robert。我已经提取出使用直接组件的公共部分。不过,在这条支线上仍有一些步骤,我希望避免重复。Apache camel doc表示AOP已被弃用。那么,有没有更好的方法来实现关于建议的AOP呢?你能解释一下为什么这些步骤不能成为公共流程的一部分(或者举个例子),让我更好地理解这个问题吗?