路由在聚合期间如何识别文件结尾?

时间:2019-09-18 08:50:02

标签: apache-camel aggregate

我是骆驼的新手。 我有一个场景。        1.提取文件        2.验证文件记录        3.如果记录正确,则发送seda1        4.如果记录不正确,发送seda2        5.汇总每条记录,并生成文件(正确的文件,错误的文件)

要实现此方案,我使用拆分和聚合EIP。 在实施过程中,我遇到了一些问题。 问题在于聚合逻辑中没有标识文件的末尾。

以下是我的关注。 1.如果文件的最后一条记录的标志值为true,errorAgregate是否可以识别CamelSplitComplete = true? 2.因为第二条记录的标志值是false,所以将其旋转到ErrorAgregate,并最终将记录包含为toCorrectAgregate。为什么?

如何处理此问题?

xml路由

   <routes id="fileCopyRoutes" xmlns="http://camel.apache.org/schema/spring">
    <route id="toServer">
        <from uri="file:/home/test/beanio?charset=iso-8859-1" />
        <!--<convertBodyTo type="java.lang.String"/>-->
        <unmarshal ref="testbeanIO" />
        <bean id="_validateParsing" method="arrayListRuleExecutor" ref="droolsExecutor"/>
        <split streaming="true">
            <simple>${body}</simple>
            <choice id="checkRecord">
                <when id="collectRecord">
                    <simple>${body[flag]} == true</simple>
                    <to uri="seda:correctAggregate"/>
                </when>
                <otherwise id="errorRecord">
                    <to uri="seda:errorAggregate"/>
                </otherwise>
            </choice>
        </split>
    </route>
    <route id="toCorrectAggregate">
        <from uri="seda:correctAggregate?concurrentConsumers=10"/>
        <log id="complete1" loggingLevel="WARN" message="${header.CamelSplitComplete}"/>
        <aggregate id="correctAggregate" strategyRef="arrayListAggregator" aggregationRepositoryRef="myRepo" eagerCheckCompletion="true">
            <correlationExpression>
                <constant>true</constant>
            </correlationExpression>
            <completionPredicate>
                <simple>${header.CamelSplitComplete} == true</simple>
            </completionPredicate>
            <to uri="mock:correctResult"/>
        </aggregate>
    </route>
    <route id="toErrorAggregate">
        <from uri="seda:errorAggregate?concurrentConsumers=10"/>
        <log id="complete2" loggingLevel="WARN" message="${header.CamelSplitComplete}"/>
        <aggregate id="errorAggregate" strategyRef="arrayListAggregator" aggregationRepositoryRef="myRepo" eagerCheckCompletion="true">
            <correlationExpression>
                <constant>true</constant>
            </correlationExpression>
            <completionPredicate>
                <simple>${header.CamelSplitComplete} == true</simple>
            </completionPredicate>
            <to uri="mock:errorResult"/>
        </aggregate>
    </route>

结果

    [2019-09-18 17:20:55.027][Camel (tar(33)][INFO ]        [o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-1 >>> (toServer) bean[ref:droolsExecutor method:arrayListRuleExecutor] --> split[Simple: ${body}] <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.ArrayList
    , Body:[{saleDateFrom=170603, classCode=01, flag=true}, {posNumber=0, flag=false, trxForm=0, saleDate=190901}, {classCode=02, flag=true, pymTotalSvcAmt=767150034, canTotalAmt=0, canTotalCnt=0, pymTotalCnt=6059}]

    [2019-09-18 17:20:55.036][Camel (tar(33)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-3 >>> (toServer) from(file:///home/test/beanio?charset=iso-8859-1) --> choice <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{saleDateFrom=170603, classCode=01, flag=true, ktfRegNum=1028142945, serviceClass=EDI, saleDateTo=190901}

    [2019-09-18 17:20:55.066][Camel (tar(33)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-3 >>> (toServer) choice --> seda://correctAggregate <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{saleDateFrom=170603, classCode=01, flag=true, ktfRegNum=1028142945, serviceClass=EDI, saleDateTo=190901}

    [2019-09-18 17:20:55.069][Camel (tar(37)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-6 >>> (toCorrectAggregate) from(seda://correctAggregate?concurrentConsumers=10) --> log[header(CamelSplitComplete)] <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{saleDateFrom=170603, classCode=01, flag=true, ktfRegNum=1028142945, serviceClass=EDI, saleDateTo=190901}

    [2019-09-18 17:20:55.070][Camel (tar(33)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-7 >>> (toServer) from(file:///home/test/beanio?charset=iso-8859-1) --> choice <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true,         CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{posNumber=0, flag=false, trxForm=0, saleDate=190901}

    [2019-09-18 17:20:55.070][Camel (tar(37)][WARN ]        [toCorrectAggregate] false
    [2019-09-18 17:20:55.071][Camel (tar(37)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-6 >>> (toCorrectAggregate) log[header(CamelSplitComplete)] --> aggregate[true] <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{saleDateFrom=170603, classCode=01, flag=true}

    [2019-09-18 17:20:55.071][Camel (tar(33)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-7 >>> (toServer) choice --> seda://errorAggregate <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{posNumber=0, flag=false, trxForm=0, saleDate=190901}

    [2019-09-18 17:20:55.074][Camel (tar(50)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-10 >>> (toErrorAggregate) from(seda://errorAggregate?concurrentConsumers=10) --> log[header(CamelSplitComplete)] <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{posNumber=0, flag=false, trxForm=0, saleDate=190901}

    [2019-09-18 17:20:55.074][Camel (tar(50)][WARN ][toErrorAggregate] false
    [2019-09-18 17:20:55.075][Camel (tar(50)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-10 >>> (toErrorAggregate) log[header(CamelSplitComplete)] --> aggregate[true] <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{posNumber=0, flag=false, trxForm=0, saleDate=190901}

    [2019-09-18 17:20:55.077][Camel (tar(33)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-11 >>> (toServer) from(file:///home/test/beanio?charset=iso-8859-1) --> choice <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{classCode=02, flag=true, pymTotalSvcAmt=767150034, canTotalAmt=0, canTotalCnt=0, pymTotalCnt=6059}

    [2019-09-18 17:20:55.081][Camel (tar(33)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-11 >>> (toServer) choice --> seda://correctAggregate <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{classCode=02, flag=true, pymTotalSvcAmt=767150034, canTotalAmt=0, canTotalCnt=0, pymTotalCnt=6059}

    [2019-09-18 17:20:55.082][Camel (tar(34)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-14 >>> (toCorrectAggregate) from(seda://correctAggregate?concurrentConsumers=10) --> log[header(CamelSplitComplete)] <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{classCode=02, flag=true, pymTotalSvcAmt=767150034, canTotalAmt=0, canTotalCnt=0, pymTotalCnt=6059}

    [2019-09-18 17:20:55.083][Camel (tar(34)][WARN ]        [toCorrectAggregate] true
    [2019-09-18 17:20:55.083][Camel (tar(34)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-14 >>> (toCorrectAggregate) log[header(CamelSplitComplete)] --> aggregate[true] <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.HashMap
    , Body:{classCode=02, flag=true, pymTotalSvcAmt=767150034, canTotalAmt=0, canTotalCnt=0, pymTotalCnt=6059}

    [2019-09-18 17:20:55.088][Camel (tar(34)][INFO ][o.a.c.p.i.Tracer] 
    ID-ktds-PC-1568794842912-0-15 >>> (toCorrectAggregate) aggregate[true] --> mock://correctResult <<<
    , Pattern:InOnly
    , Headers:{breadcrumbId=ID-ktds-PC-1568794842912-0-1, CamelFileAbsolute=true, CamelFileAbsolutePath=C:\home\test\beanio\SL110904, CamelFileLastModified=1568693819112, CamelFileLength=549, CamelFileName=SL110904, CamelFileNameConsumed=SL110904, CamelFileNameOnly=SL110904, CamelFileParent=C:\home\test\beanio, CamelFilePath=C:\home\test\beanio\SL110904, CamelFileRelativePath=SL110904}
    , BodyType:java.util.ArrayList
    , Body:[{saleDateFrom=170603, classCode=01, flag=true}, {posNumber=0, flag=false, trxForm=0, saleDate=190901}, {classCode=02, flag=true, pymTotalSvcAmt=767150034, canTotalAmt=0, canTotalCnt=0, pymTotalCnt=6059}]

0 个答案:

没有答案