Randomize
Randomize

Reputation: 9103

Apache Camel: consuming a file after a direct

What I am trying to do is having a "jms" queue that sends a message with the body that contains the name of a file and a "header" (e.g. JMSType) that represents the route to switch to. Once the route has been switched (using "direct:") I would like to be able to consume the file indicated in the message's body but I don't know how to do it properly. This is what I mean (in a sort of pseudo code):

from('jms:whatToDo')
  .choice().header('JMSType')
    .when('this').to('direct:this')
    .when('that').to('direct:that')
    .otherwise().to('direct:nothing')
  .end()

from ('direct:this').from('file:/tmp/${jms-body()}?noop=true')
                .split(body().tokenize('\n'))...etc

I have put 2 "from"s ("direct:" and "file:") consecutively that are wrong in camel but it's to highlight what I mean.

Any idea how to reach that with Camel?

Upvotes: 2

Views: 306

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55750

You can do a message transformation to set the body to a java.io.File for the file you want to read

from ('direct:this')
  .transform(simple("file:/tmp/${body}", java.io.File.class))
  .split(body().tokenize('\n'))...etc

Upvotes: 4

Related Questions