camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Claus Ibsen <claus.ib...@gmail.com>
Subject Re: Move file when message received
Date Fri, 13 Jul 2012 05:46:30 GMT
On Thu, Jul 12, 2012 at 9:31 PM, RobO <rogando@book.com> wrote:
> Hi.
>
> I have the name of a file I want to move contained in the message header of
> a JMS message. I'd like to get the file name from the message header and
> move that file to another directory. I have successfully written this route
> using a bean however I've been thinking if it would be possible with out
> using the bean.
> Here is essentially what I want to do, although it doesnt work.
>
>                  from("activemq:queue:myfiles")
> subroute-->       .from("file://?fileName=${header.FromFile}")
>                        .to("file://?fileName=${header.ToFile")
>
> Any ideas on how to do this?
>

Hi

You can write 2 lines of java code to move the file with java.io.File API.
                  from("activemq:queue:myfiles")
                     .bean(MyMoveFileClass.class)



And invoke a bean / processor from the Camel route. You can use the
@Header to bind the headers to parameters
http://camel.apache.org/bean-binding.html

public static void moveMyFile(@Header("FromFile") String fromFile,
@Header("ToFile") String toFile) {
   File from = new File(fromFile);
   if (from.exists()) {
      from.renameTo(new File(toFile));
   }
}



> Thanks
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Move-file-when-message-received-tp5715968.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Mime
View raw message