Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel FTP - How to start the route manually

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

like image 599
publicMee Avatar asked May 12 '15 09:05

publicMee


People also ask

How do you manually start a Camel route?

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.

How do you make a Camel route?

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.

How do you start a 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.


2 Answers

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.

like image 129
Ramin Arabbagheri Avatar answered Jan 01 '23 07:01

Ramin Arabbagheri


Read the documentation about how to configure routes to not auto start:

  • http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html

Then check out the control bus EIP which allows to start routes from other routes

  • http://camel.apache.org/controlbus.html

And this FAQ talks about stopping a route, but starting would be similar

  • http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html

And there is also API on CamelContext to start route, or you can use JMX.

like image 42
Claus Ibsen Avatar answered Jan 01 '23 07:01

Claus Ibsen