We have an XML configuration with Camel routes that includes this bean to configure spooling to disk for large messages:
<streamCaching id="diskSpoolConfig" bufferSize="16384" spoolEnabled="true" spoolThreshold="10000000"/>
I'd like to configure Camel so streamCaching uses disk-spooling automatically, without having to specify this in the XML config. The Camel instance is started from a JAR with
Main main = new Main();
main.setApplicationContextUri("file:routes.xml");
main.run();
I found doc about application.properties
and set
camel.main.streamCachingSpoolEnabled=true
but I'm unclear where this file needs to reside in the JAR so it gets read. I also tried with
Main main = new Main();
main.addMainListener(new MainListenerSupport() {
public void beforeConfigure(BaseMainSupport main) {
CamelContext context = main.getCamelContext();
context.setStreamCaching(true);
context.getStreamCachingStrategy().setSpoolEnabled(true);
context.getStreamCachingStrategy().setSpoolThreshold(10 * 1024 * 1024);
}
});
main.setApplicationContextUri("file:routes.xml");
main.run();
That was also ineffectual. Maybe it gets applied too late? Because for example when I set context.getShutdownStrategy().setTimeout(5);
in beforeConfigure()
, it has an effect.
How can I start a Camel instance with disk-spooling enabled?
It is possible to create a context from multiple config files. This allows having presets inside the jar, but loading routes from outside:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"classpath:preset.xml",
"file:routes.xml"
);
Main main = new Main();
main.setApplicationContext(context);
main.run();