Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot properties usage in Apache Camel route

Is this possible to use Spring Boot properties in Apache Camel route? @Value is working fine but is this possible to directly place in place holders of expressions.

Update: I know PropertiesComponent but which will be one more configuration apart from Applicaiton.yml that I don't like to have.

application.yml

sftp:
  host:     10.10.128.128
  user:     ftpuser1
  password: ftpuser1password  
  path:     /tmp/inputfile/test1

Spring Boot Apache Camel Route:

 @Value("${sftp.user}")
    private String sftpUser;

    @Value("${sftp.host}")
    private String sftpHost;

    @Value("${sftp.password}")
    private String sftpPassword;

    @Value("${sftp.path}")
    private String sftpInPath;

    from("sftp://"+sftpUser+"@"+sftpHost+sftpInPath+"?delete=true&password="+sftpPassword)
//this is working

    from("sftp://${sftp.user}@${sftp.host}${sftp.path}?password=${sftp.password}")
// is this possible something like this?
like image 926
sunleo Avatar asked Aug 08 '17 11:08

sunleo


2 Answers

You can use property placeholders (http://camel.apache.org/properties.html) in Camel like this:

from("sftp://{{sftp.user}}@{{sftp.host}}{{sftp.path}}?password={{sftp.password}}")
like image 130
mgyongyosi Avatar answered Nov 12 '22 10:11

mgyongyosi


Instead of injecting all you properties to separate fields you can inject your full link like that:

@Value("#{'sftp://'+'${sftp.user}'+'@'+'${sftp.host}'+'${sftp.path}'+'?delete=true&password='+'${sftp.password}'}")
private String fullLink;

Then, you can use it in from method.

like image 34
ByeBye Avatar answered Nov 12 '22 12:11

ByeBye