CAMEL-24321: Allow stream caching spool directory to be resolved per-Exchange - #25360
CAMEL-24321: Allow stream caching spool directory to be resolved per-Exchange#25360gnodet wants to merge 1 commit into
Conversation
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 558 tested, 29 compile-only — current: 558 all testedMaveniverse Scalpel detected 587 affected modules (current approach: 558).
|
…Exchange Add resolveSpoolDirectory(Exchange) default method to StreamCachingStrategy interface. The default delegates to getSpoolDirectory(), so existing custom implementations continue to work unchanged. CachedOutputStream now stores the Exchange and passes it through to TempFileManager.createOutputStream(), which calls the new method instead of the zero-arg getSpoolDirectory(). This allows custom StreamCachingStrategy implementations to return a per-route or per-exchange spool directory, enabling spool data isolation and per-route monitoring of spool usage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
797f92e to
a021dbe
Compare
Summary
Allow the stream caching spool directory to be resolved per-Exchange, so custom
StreamCachingStrategyimplementations can direct each route's spooled bytes to a separate directory.Problem: The spool directory is resolved once at startup in
DefaultStreamCachingStrategy.doStart()and stored as a single context-wideFile. TheExchangeis available inCachedOutputStream's constructor but is dropped before the spool directory is selected inTempFileManager.createOutputStream(). This makes it impossible for custom strategies to make per-route decisions.Fix (3 source files, 1 test file):
StreamCachingStrategy(camel-api): Adddefault File resolveSpoolDirectory(Exchange exchange)method that falls back togetSpoolDirectory(). Full backward compatibility — existing custom implementations compile and work unchanged.CachedOutputStream(camel-support): Store theExchangeas a field and pass it throughpageToFileStream()toTempFileManager.createOutputStream().FileInputStreamCache.TempFileManager(camel-support): Callstrategy.resolveSpoolDirectory(exchange)instead ofstrategy.getSpoolDirectory(). Create the resolved directory on-demand if it doesn't exist.Usage example:
Test plan
testDefaultResolveSpoolDirectoryReturnsSameDirectory— default behavior unchangedtestPerExchangeSpoolDirectoryResolution— custom strategy routes to per-route subdirectorytestPerExchangeSpoolDirWithDifferentRoutes— two routes spool to different subdirectoriestestPerExchangeSpoolDirFallsBackWhenNoRouteId— falls back to base directory when no route IDCachedOutputStreamTesttests pass (8/8)StreamCaching*Testtests pass (18/18)🤖 Generated with Claude Code on behalf of @gnodet