5 Replies Latest reply on Aug 27, 2009 1:48 PM by davsclaus

    How to consume a specific file with camel

    gvanstad

      Hi.

       

      I need to consume a specific file using camel.

       

      According to the manual I have to set fileName=thefilename, but this does not work.

       

      How can I configure my source URI in order to only consume files with a specific name?

        • 1. Re: How to consume a specific file with camel
          davsclaus

          Which version of Camel are you using?

           

          And what did you do that you think are not working? Eg post your route configuration.

           

          And do you want to consume the file during a route or from the start?

          • 2. Re: How to consume a specific file with camel
            gvanstad

            Hi.

             

            I'm using Fuse ESB 4.

             

            I am doing everything in an OSGI bundle.

            The route-ref is setup in my bundle-context.xml

            I then use a java class that extends RouteBuilder to execute the route

             

            basically, I want to:

            • detect a trigger file with a specific name (Starting point of my route)

            • consume 2 separate files with specific names

            • transform both files from fixed-width to XML

            • send transformed output to 2 seperate active MQ queues.

             

            Here's my bundle-context.xml

             

             

            • 3. Re: How to consume a specific file with camel
              davsclaus

              Hi

               

              Look at the Camel 1.x file documentation at:

              http://camel.apache.org/file

               

              Use the consumer.regexPattern to set a regular expression with the filename pattern you want to match.

               

              For example: ^me.*xml$ to match files starting with me and ending with xml.

              • 4. Re: How to consume a specific file with camel
                gvanstad

                Great! Thanks!

                 

                One more question though:

                 

                my process is triggered by a file arriving in a folder. Once this file is consumed, I need to consume 2 specific files from the same folder and process them.

                 

                How would you approach a situation like this?

                I understand that every from(...) starts a new route?

                • 5. Re: How to consume a specific file with camel
                  davsclaus

                  You dont have to shoehorn everything into Camel.

                   

                  You could just read the files manually using a processor / pojo.

                   

                  You can also use the Camel type converter to easily read the file

                   

                  File file = new java.io.File("my file name goes here");
                  String context = exchange.getContext().getTypeConverter().convertTo(String.class, file);
                  

                   

                  You can also consume the files from a processor as shown in the FTP wiki page here:

                  http://camel.apache.org/ftp.html

                   

                  In the section - Consuming a remote FTP server triggered by a route