I have just started to use Camel in one of my projects. I am trying to configure Camel with Spring, but having issues doing that.
I don't want to use xml configuration but rather go with Spring based Annotations for configuring Routes and Processors.
My App is a stand alone Spring Application, which will be run as Jar. To keep the app running, I've a empty scheduled method which runs every x min.
Below are the dependencies in my build.gralde
// Spring //
compile('org.springframework:spring-core:5.0.0.RC2')
compile('org.springframework:spring-context:5.0.0.RC2')
compile('org.springframework:spring-beans:5.0.0.RC2')
compile('org.springframework:spring-context-support:5.0.0.RC2')
// Apache //
// Camel //
compile('org.apache.camel:camel-core:2.19.1')
compile('org.apache.camel:camel-spring:2.19.1')
snapshot of beans.xml
<context:annotation-config/>
<tx:annotation-driven/>
<context:component-scan base-package="my.package" />
<camelContext id="aggregatorCamelContext" autoStartup="true" xmlns="http://camel.apache.org/schema/spring">
<package>
my.package.camel
</package>
</camelContext>
Sample RouteBuilder
@Component
public class SampleRoute extends RouteBuilder {
@Autowired
MyClass myObject;
@Override
public void configure() throws Exception {
from("file:filelist")
.process(myObject)
.to("file:processedList");
}
}
To keep the app alive ( I know bit hacky, but suffices for now )
@Component
@EnableScheduling
public class KeepitAlive {
@Scheduled(fixedRate = 1000l)
public void run(){
System.out.println("KeepitAlive.run "+ Thread.currentThread().getName() );
}
}
Main Class. I have tried both the methods, Initializing Spring context as well as Camel Main, but to no luck
public class MyApplication {
public static void main(String[] args) throws Exception {
/*AbstractXmlApplicationContext context =
new ClassPathXmlApplicationContext("path/to/beans.xml");*/
Main main = new Main();
main.setApplicationContextUri("path/to/beans.xml");
main.start();
}
}
If I put my Route within camelContext declaration itself, it works absolutely fine,
<route>
<from uri="file:filelist"/>
<to uri="file:processedlist"/>
</route>
I've also looked into Camel Spring Integration documentation, but it also contains xml based configuration.
Could anybody please guide me in right direction.
run
method on theMain
class if its from Apache Camel. See this FAQ: camel.apache.org/… – Claus Ibsen