Reputation: 4378
I have a batch route that consumes XML files from a folder. It filters, transforms and finally saves a grouped document to disk. As this is a batch route, I require it to be shut down after a single polling of the sourcefolder, which is what the RouteTerminator is for in the code below. (It calls stopRoute()
and removeRoute()
on camelContext
with routeID
.)
from("file:" + sourcePath)
.filter().xquery("//DateTime > xs:dateTime('2013-05-07T23:59:59')")
.filter().xquery("//DateTime < xs:dateTime('2013-05-09T00:00:00')")
.aggregate(constant(true))
.completionFromBatchConsumer()
.groupExchanges()
.to("xquery:" + xqueryPath)
.to("file:" + targetPath)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
new RouteTerminator(routeID, exchange.getContext()).start();
}
})
.end();
This correctly closes the route after a single file collection and after repeating the process in onException
it also gracefully closes the route when an exception is thrown. Unfortunately, if the route filters out every Exchange, it never reaches the processor. Exchanges are instead dropped during the filter and the route remains open.
I thought to move the filter inside the aggregate
call as this might keep the route going until the end, but this method won't accept XQuery filters. XPath is not an option as it does not support dateTime comparisons.
How can I force the entire route to stop in this case?
Upvotes: 0
Views: 112
Reputation: 24627
I tried again and now have a solution where I call setHeader to set a Filtered header.
Unfortunately I can't seem to break out of the choice to use it as a simple switch/case so I have to route both the .when() and .otherwise() to the same second direct route.
In that route I then aggregate and call a basic merge bean that builds a Document out of every Exchange and adds it to a GenericFile if the header matches. It seems like there should be an easier way to simply set a header based on an xquery though...
Upvotes: 1