与xslt聚合

loading...


0

我试图从数据库中获取数据后聚合消息 . 似乎很难解释,我将首先绘制一个流程 .

[ORIGINAL_DOCUMENT] --> SPLIT[GET SOME IDs from ORIGINAL_DOCUMENT] --> [GET DATA FROM DATABASE USING MYBATIS] --> [ENRICH ORIGINAL_DOCUMENT BY GOT DATA FROM DATABASE]

第一条路线:

<route id="enrich-zamowienie">
        <from uri="activemq:queue:original-document"/>

        <setHeader headerName="pure-xml">
            <simple>${body}</simple>
        </setHeader>

        <split>
            <xpath>original-document/entry</xpath>

            <unmarshal>
                <jaxb contextPath="com.original-document"/>
            </unmarshal>

            <setBody>
                <simple>${body.getEntryId()}</simple>
            </setBody>

            <to uri="activemq:queue:getAdditionalsByID" />

            <marshal>
                <jaxb contextPath="com.additionals"
                      encoding="utf-8" prettyPrint="true"/>
            </marshal>

            <setHeader headerName="entry">
                <simple>${body}</simple>
            </setHeader>

            <setBody>
                <simple>${header.pure-xml}</simple>
            </setBody>

            <to uri="direct:aggregate" />
        </split>
    </route>

第二条路线:

<route>
        <from uri="direct:aggregate" />

        <aggregate strategyRef="aggregator">
            <correlationExpression>
                <xpath>?</xpath>
            </correlationExpression>
        </aggregate>

        <log message="${body}" />
    </route>

    (...)
    <bean id="aggregator" class="org.apache.camel.util.toolbox.XsltAggregationStrategy">
    <constructor-arg value="com/transformXSLT.xsl" />

我的原始xml,我从acyvemq获得:

<document>
    <header>
        <header_id>1</header_id>
    </header>
    <body>
        <entry>
            <entryId>1</entryId>
            <fieldToEnrich1></fieldToEnrich1>
            <fieldToEnrich2></fieldToEnrich2>
            <fieldToEnrich3></fieldToEnrich3>
        </entry>
        <entry>
            <entryId>2</entryId>
            <fieldToEnrich1></fieldToEnrich1>
            <fieldToEnrich2></fieldToEnrich2>
            <fieldToEnrich3></fieldToEnrich3>
        </entry>
        <entry>
            <entryId>3</entryId>
            <fieldToEnrich1></fieldToEnrich1>
            <fieldToEnrich2></fieldToEnrich2>
            <fieldToEnrich3></fieldToEnrich3>
        </entry>
    </body>
</document>

每个id addtional的coure看起来像:

<document>
    <additionals>
        <fieldToEnrich1>131</fieldToEnrich1>
        <fieldToEnrich2>3232</fieldToEnrich2>
        <fieldToEnrich3>3213</fieldToEnrich3>
    </additionals>
</document>

我的目标是通过数据库中的额外数据创建像original_document这样的文档 . 我不知道如何看第二条路线 . 我希望这是可以理解的 .

loading...

1回答

  • 0

    我不知道我是否完全理解您要如何合并文档,但我认为您希望通过 entry 拆分原始XML并将每个条目与 additionals 合并 .

    由于这只是 single merge of two documents (为每个 entry 完成)而不是重复合并,因此可以使用Enrich EIP而不是Aggregator . 它还采用聚合策略来决定如何合并两个文档 .

    您只需使用XSL作为聚合策略,使用 additionals XML(从另一个路径检索)丰富 entry XML

    <route id="enrich-zamowienie">
        <from uri="activemq:queue:original-document"/>
        ...
    
        <split>
            <xpath>original-document/entry</xpath>
            ... [body is a single entry]
            <enrich uri="direct:routeThatLoadsAdditionals" strategyRef="yourAggregatorStrategyBean"/>
            ... [body is a merge of entry and additionals]
        </split>
    </route>
    
    <route id="load-additionals-for-entry">
        <from uri="direct:routeThatLoadsAdditionals"/>
        ... [load additionals and set additionals XML as body]
        ... [the body of this message is merged with the body of caller message]
    </route>
    

    这样,您可以清楚地分离附加文档的创建和拆分器中的简化逻辑 .

评论

暂时没有评论!