Kalithas Sendrayan created CAMEL-24321:
------------------------------------------

             Summary: Stream caching: allow the spool directory to be resolved 
per-Exchange
                 Key: CAMEL-24321
                 URL: https://issues.apache.org/jira/browse/CAMEL-24321
             Project: Camel
          Issue Type: Improvement
          Components: came-core
    Affects Versions: 4.14.2
            Reporter: Kalithas Sendrayan


h3. Use case

Multi-route runtimes need each route's spilled bytes to go to a caller-decided
directory. For example:
 * We need each route's spool data isolated (route A's payloads must not share 
a directory with route B's)
 * We need to monitor spool directory usage at the route level

h3. Current behavior

Stream caching is scoped per CamelContext: the spool directory is resolved once
at startup (DefaultStreamCachingStrategy.doStart() via TempDirHelper) into a
single directory. Every route that spills to disk uses that one context-wide
directory.
h3. Limitation

The Exchange is available where CachedOutputStream is constructed (and it 
carries
the route id via getFromRouteId()), but it is dropped before the directory is
chosen. 
FileInputStreamCache.TempFileManager.createOutputStream(StreamCachingStrategy)
resolves the location from the no-arg strategy.getSpoolDirectory() and never 
sees
the Exchange:
{code:java}
tempFile = FileUtil.createTempFile("cos", ".tmp", strategy.getSpoolDirectory());
{code}
So even a custom StreamCachingStrategy cannot make a per-route decision - the
information it needs - the Exchange, from which the route id is available - is
not passed to the point where the directory is selected.
h3. Expected capability

A way to choose the spool directory per route (per Exchange), so a custom
StreamCachingStrategy can direct each route's spilled bytes to its own 
directory.
h3. Steps to reproduce
 # Configure stream caching with spooling enabled (low spool threshold).
 # Deploy two routes intended to spill into different directories.
 # Send a large body (over the threshold) to each so both spill to disk.
 # Both temp files land in the same context-wide spool directory - there is no
API to make them differ per route.

h3. Environment / version

Reproduced on Apache Camel 4.14.2. The stream-cache classes are in camel-support
(CachedOutputStream, FileInputStreamCache); the strategy is in camel-base-engine
(DefaultStreamCachingStrategy).
h3. Relevant implementation references
 * org.apache.camel.converter.stream.CachedOutputStream (camel-support)
 * org.apache.camel.converter.stream.FileInputStreamCache (camel-support; inner 
TempFileManager)
 * org.apache.camel.impl.engine.DefaultStreamCachingStrategy 
(camel-base-engine; doStart via TempDirHelper)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to