0

I hava file1.jpg,file2.jpg,file3.jpg in DirA. I have file1.json,file2.json,file3.json in DirB

How can I create a apache camel file route such that first route picks file1.jpg from a DirA , processes and pass file1 name to second route so that it can read file1.json and processes.

CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
            public void configure() {
from("file:///DirA/?noop=true"). bean(MyBean.class,"doSomeThingWithJPG(${file:absolute.path})").

from("file:///DirB/?noop=true&fileName=${file:name}.json").
bean(AnotherBean.class,"doSomeThingWithJSON(${file:absolute.path})") ;
    } 
 }) 

The second from (file:///) component is also pointing to file in DirA instead of files in DirB

shyamsrd
  • 49
  • 4
  • 1
    You want to read the files from DirA. What do you want to do with the files from DirB? Do you want to read from DirA and *create* files in DirB? – Darius X. May 31 '19 at 03:03
  • @DariusX. I read file.jpg from DirA and uploads to AWS s3. After successful upload, I want to upload a file.json from DirB to s3 which contains metadata about jpg. This metadata file will trigger lambda and upstream system pulls jpg file. – shyamsrd May 31 '19 at 12:38
  • Ah! So, why not let the second route simply listen for all/any file in DirB. Whenever the JSON file arrives there, the second route will process it. It does not need to know the name beforehand. – Darius X. May 31 '19 at 13:22
  • @DariusX. I want to make sure the file1.jpg is successfully uploaded and available when metadata file1.json is uploaded. If file1.json uploaded first and it triggers the lambda, file1.jpg was not uploaded yet, it will cause issue. So I need a sequence such that Route1 starts first and then route 2. Also I need a way from route1 file name part is passed to route2 – shyamsrd May 31 '19 at 15:15

1 Answers1

1

You could:

  • Stage the JSON file
  • Write a processor or bean that copies a named file from one directory to another
  • Call that processor after processing JPG, to copy the JSON to another directory
  • Have the second file-listener polling that other directory

enter image description here

Darius X.
  • 2,886
  • 4
  • 24
  • 51