camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "lakshmi.prashant" <>
Subject Streamcache issue - deletion of spooled files in multicast sub exchanges before aggregationstrategy
Date Fri, 05 Sep 2014 11:18:47 GMT
Mybeans.xml <>  


  Whenever data is spooled in file via CachedOutputStream in any camel
component in a multicast branch, that data becomes unreadable in 

a) Aggregation Strategy of Multicast 
b) After multicast, in case there is no aggregation strategy 

We are getting: 

a) FileNotFound issues as the file is deleted on completion of the cloned
branch exchange. 
b) Premature end of file, when we read data from InputStream and use
XMLReader / STAX to read the data. 

If we use the Constructor: new CachedOutputStream(exchange, false), the
streamcache file will not be deleted. 
But the file may never be cleaned up & we do not want to do that. 


 We are using camel 2.13.2  - I have a multicast route with an
 And in each multicast branch, we have a custom camel component that returns
huge data (around 4 MB) and writes to StreamCache (CachedOutputStream) and
we need to aggregate the data in the multicast (AggregationStrrategy). 

  In the Aggregation strategy, I need to do XPath evaluation using camel
  Hence, I try to read the body and convert from StreamCache to byte[] to
avoid 'Error during type conversion from type:' in the XPathBuilder. 

When I try to read the body in the beginning of the AggregationStrategy, I
get the following error. 

(No such file or directory), cause:
(No such file or directory). 
        at Method) 





Following is the line of code where it is throwing an error: 
                            Object body = exchange.getIn().getBody(); 
                if( body instanceof StreamCache){ 
                        StreamCache cache = (StreamCache)body; 
                        xml = new


By disabling stream cache to write to file by setting a threshold of 10MB in
multicast related routes,  we were able to work with the aggregation
strategy. But we do not want to do that, as we may have incoming data that
maybe bigger. 

<camel:camelContext id="multicast_xml_1" streamCache="true">
<camel:property key="CamelCachedOutputStreamCipherTransformation"
<camel:property key="CamelCachedOutputStreamThreshold" value="100000000"/>

Note: The FileNotFound issue does not appear if we have the StreamCache
based camel component in the route with other processors, but without
Multicast + Aggregation . 

After debugging, I could understand the issue with aggregating huge data
from StreamCache with MulticastProcessor. 

In doProcessParallel() is called and on completion
of the branch exchange of multicast, the CachedOutputStream deletes / cleans
up the temporary file. 

 This happens even before the multicast branch exchange reaches the
aggregation Strategy, which tries to read the data from the branch exchange.
In case of huge data in StreamCache, the temporary file is already deleted,
leading to FileNotFound issues. 

    public CachedOutputStream(Exchange exchange, boolean closedOnCompletion)
        this.strategy = exchange.getContext().getStreamCachingStrategy(); 
        currentStream = new
        if (closedOnCompletion) { 
            // add on completion so we can cleanup after the exchange is
done such as deleting temporary files 
            exchange.addOnCompletion(new SynchronizationAdapter() { 
                public void onDone(Exchange exchange) { 
                    try { 
                        if (fileInputStreamCache != null) { 
                        close();                    } catch (Exception e) { 
                        LOG.warn("Error deleting temporary cache file: " +
tempFile, e); 
                public String toString() { 
                    return "OnCompletion[CachedOutputStream]"; 

   public void close() throws IOException { 

I was able to circumvent the issue, if I try to set closedOnCompletion=
false, while writing to CachedOutputStream in any component in any Multicast
But this is a leaky solution, because the streamcache temporary file(s) may
then never get cleaned up. 

Can the MulticastProcessor be adjusted so that the multicast branch
exchanges reach 'completion' status only, after they have been aggregated at
the end of multicast? 

Please help / advise on the issue, as I am new to using camel Multicast. 

View this message in context:
Sent from the Camel Development mailing list archive at

View raw message