0
votes

Am trying to create generic route to transfer file using Apache Camel component.

Scenario:

  • multiple source files present on multiple servers.
  • need to ftp the file to destination server.

Is there any way we can have from and to endpoint which can read the source and destination configurations from properties and route the files?

In this case if we need to add more source and destination, we just need to change the properties file. As am aware we cannot have dynamic from endpoint in Apache Camel.

Example:

{server1-file1} - camel route(Generic) - {server2-file1}
{server1-file1} - camel route(Generic) - {server2-file1}
{server1-file1} - camel route(Generic) - {server2-file1}
1

1 Answers

1
votes

To address this particular problem, you create a Camel route in Java that allows you to inject a start URI, and an end URI. This idea is called route templating. An example of this is:

public class FtpTemplateRoute extends RouteBuilder {
    private String startUri;
    private String endUri; 

    public FtpTemplateRoute(String startUri, String endUri) {
        this.startUri = startUri;
        this.endUri = endUri;
    }

    public void configure() {
        from(startUri)
           ...
           .to(endUri);
    }
}

You then instantiate it X number of times, when you're setting up your CamelContext:

CamelContext context = new DefaultCamelContext();
context.addRoutes(
    new FtpTemplateRoute("ftp:///dirA", "ftp:///dirB"));
context.addRoutes(
    new FtpTemplateRoute("ftp:///dirC", "ftp:///dirD"));

It's up to you how you want to load the source and target uris.