apache-camelspring-camelcamel-ftp

Camel FTP Route calling another Route


I have an FTP route which processes an inbound text file and call's a company API to load that data into an internal Company table. All works perfect.

I now have a case where when the FTP route is invoked, I first need to remove all the existing data from the Company table... there is a company API to handle that case.

The problem I have is that the Company API which removes data from the Company table also returns some information relative to the delete operation.

In this special case, I would normally want to first delete all records in the Company table ( using this Company API call ) and THEN process the inbound FTP data file.

The issue is that if I begin the ftp processing ( Step 1 ) and then call the company API ( Step 2 ) to first delete the exiting data in the table, the inbound data from the file associated with the FTP operation is lost prior to executing Step 3 ...what is in the context appears to be the data returned from Step 2.

Ideally, I would like the route to start ( Step 1 ) and be able to call Step 2 without destroying the data inbound from the FTP file ...is there a way to accomplish this ? I know how to call one route from another, just not how to prevent the FTP data from being lost when I do make the call to the other route.

<route id="import-data-from-ftp">
  
  <from uri="ftp: .............................">              Step 1
  
     <to uri="api:deleteData ............................." >  Step 2
     
     <to uri="api:loadData ............................." >    Step 3

Solution

  • I'm gonna comment this because I don't have the 50 reputation for comment, but is better use properties, this is because the headers can be lost every time you call an api and the properties will not be delete, so you can save the body inside a property for example

    <route id="import-data-from-ftp">
      
      <from uri="ftp: .............................">              Step 1
      
        <setProperty name="preservedbody">
            <simple>${bodyAs(String)}</simple>
        </setProperty>
    
         <to uri="api:deleteData ............................." >  Step 2
         
        <setBody>
            <exchangeProperty>preservedbody</exchangeProperty>
        </setBody>
    
         <to uri="api:loadData ............................." >    Step 3