This Camel route should start reading files from a Ftp-Server:
from("sftp://user@...")
Now, I don't want this to start automatically, or polling, or similar. This should be started manually (externally, JMX). I have other routes which are being triggered via a MBean, and I use for that the direct label:
from("direct:myRoute1")
Which is the best way to do the same and starting as the first action with an FTP-read functionality? Something like:
from("direct:myRoute2")
.from("sftp://user@...")
.autoStartup(false)
? This is not working. After the manual-JMX-trigger no file is being ftp-read. I guess the two "from" starting the route work in parallel and therefore starting the "direct:myRoute2" does not trigger the FTP.
Kann I put the FTP-URI in another component, other than "from", to start the FTP-Read after the from("direct:myRoute2")?
BTW: This is an individual route, with no connection with other routes.
Thanks
The autoStartup option on the <camelContext> is only used once, so you can manually start Camel later by invoking its start method in Java as shown below. For example when using Spring, you can get hold of the CamelContext via the Spring ApplicationContext : ApplicationContext ac = ... CamelContext camel = ac.
To create a route in Camel, you first define it in code. This is called a route definition, and it is usually written in Java or XML. Then, you start Camel, passing it your route definition. Camel reads the route definition and creates the route inside the Camel Context.
CamelContext context = new DefaultCamelContext(); try { context. addRoutes(new RouteBuilder() { // Configure filters and routes } } ); The DefaultCamelContext class provides a concrete implementation of CamelContext. In addRoutes method, we create an anonymous instance of RouteBuilder.
What you need is Poll Enrich:
from("direct:myRoute2")
.pollEnrich("ftp://localhost")
.to("mock:result");
Now trigger the direct (no matter what you send to it) and the ftp consumer starts.
Read the documentation about how to configure routes to not auto start:
Then check out the control bus EIP which allows to start routes from other routes
And this FAQ talks about stopping a route, but starting would be similar
And there is also API on CamelContext to start route, or you can use JMX.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With