Created
July 22, 2016 20:55
-
-
Save dlwhitehurst/168073a3666e5859f44da6c8340a9a75 to your computer and use it in GitHub Desktop.
This custom agreggator for Scatter-Gather was the only solution I've found to aggregating multiple collections with the same root tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.hoeggsoftware; | |
import org.mule.api.MuleEvent; | |
import org.mule.api.MuleException; | |
import org.mule.api.context.MuleContextAware; | |
import org.mule.api.routing.AggregationContext; | |
import org.mule.routing.AggregationStrategy; | |
import org.mule.api.MuleContext; | |
import org.mule.api.routing.RouterResultsHandler; | |
import org.mule.routing.DefaultRouterResultsHandler; | |
/** | |
* @author <a href="mailto:[email protected]">David L. Whitehurst</a> | |
* | |
*/ | |
public class CustomAggregator implements AggregationStrategy, MuleContextAware { | |
private RouterResultsHandler resultsHandler = new DefaultRouterResultsHandler(); | |
private MuleContext muleContext; | |
@Override | |
public MuleEvent aggregate(AggregationContext context) throws MuleException { | |
MuleEvent result = null; | |
// for (MuleEvent event : context.collectEventsWithoutExceptions()) { | |
// result = DefaultMuleEvent.copy(event); | |
// result = resultsHandler.aggregateResults(eventsWithoutExceptions, context.getOriginalEvent(), muleContext); | |
// } | |
result = resultsHandler.aggregateResults(context.collectEventsWithoutExceptions(), context.getOriginalEvent(), muleContext); | |
for (MuleEvent event : context.collectEventsWithExceptions()) { | |
System.out.println(event.getMessageAsString()); | |
} | |
if (result != null) { | |
return result; | |
} | |
throw new RuntimeException("Scatter-Gather data could not be collected!"); | |
} | |
@Override | |
public void setMuleContext(MuleContext context) { | |
this.muleContext = context; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment