所有路由器完成执行后的聚合结果

时间:2013-08-26 23:18:41

标签: mule

一旦所有路由器完成处理,是否可以执行某些操作。 all路由器有3个不同的子流,它们是异步执行的。一旦所有子流程完成执行。我需要执行逻辑来确定哪个失败了,哪个失败了。我应该实现聚合器吗?有人可以提供一个例子。

<flow name="InvalidFlow2" doc:name="InvalidFlow2">
    <file:inbound-endpoint responseTimeout="10000" doc:name="File" path="c:\filelanding\in4" pollingFrequency="100" connector-ref="input_4">
        <file:filename-regex-filter pattern="(?!.*Processed|.*Failed)(.*)" caseSensitive="false"/>
    </file:inbound-endpoint>
    <message-properties-transformer doc:name="Message Properties">
        <add-message-property key="Source_System" value="XXXX"/>
    </message-properties-transformer>
    <!-- Test  Component causes a delay of 20 sec....-->
    <test:component waitTime="20000"></test:component>
    <object-to-string-transformer doc:name="Object to String"/>

    <all doc:name="All">
        <async doc:name="Async">
            <flow-ref name="TesterFlow1" doc:name="Flow Reference"/>
        </async>
        <async doc:name="Async">
            <flow-ref name="TesterFlow3" doc:name="Flow Reference"/>
        </async>
        <async doc:name="Async">
            <flow-ref name="TesterFlow2" doc:name="Flow Reference"/>
        </async>
    </all>
    <flow-ref name="TesterFlow4" doc:name="Flow Reference"/>
        <!-- if any one fails remove the processing file or move processing file to processed after completion of the all router -->
    <exception-strategy ref="fot_exception_strategy_multiple" doc:name="Reference Exception Strategy"/>
</flow>

<flow name="TesterFlow4" doc:name="TesterFlow4">
    <custom-aggregator failOnTimeout="true" class="com.XXX.XXX.service.AggregateResults" doc:name="Custom Aggregator"/>
    <component class="com.XXX.XXX.service.MoveProcessedFiles" doc:name="Java"/>
</flow>

我添加了一个自定义聚合器,如下所示

public class AggregateResults extends AbstractAggregator{

@Override
protected EventCorrelatorCallback getCorrelatorCallback(MuleContext muleContext) {
     return new CollectionCorrelatorCallback(muleContext,false,storePrefix)
        {
         @Override
            public MuleEvent aggregateEvents(EventGroup events) throws AggregationException
            {
                StringBuffer buffer = new StringBuffer(128);

                try
                {
                    for (Iterator<MuleEvent> iterator = events.iterator(); iterator.hasNext();)
                    {
                        MuleEvent event = iterator.next();
                        try
                        {
                            buffer.append(event.transformMessageToString());
                        }
                        catch (TransformerException e)
                        {
                            throw new AggregationException(events, null, e);
                        }
                    }
                }
                catch (ObjectStoreException e)
                {
                    throw new AggregationException(events,null,e);
                }

                logger.debug("event payload is: " + buffer.toString());
                return new DefaultMuleEvent(new DefaultMuleMessage(buffer.toString(), muleContext), events.getMessageCollectionEvent());
            }
        };
}

}

0 个答案:

没有答案