简体   繁体   中英

Apache Camel multiple consumers

I've been working with Apache Camel for a while and doing some basic stuff, but now I'm trying to create a route in which I can have multiple "consumers" to the same route, or add a consumer to the route and then process the message.

My idea is to have an Event Driven Consumer which is triggered by an event, and then to read a file from an ftp for example. I was planning to do something like this:

from("direct:processFile")
  .from("ftp://localhost:21/folder?fileName=${body.fileName}") // etc.
  .log("Start downloading file ${file:name}.")
  .unmarshal().bindy(BindyType.Csv, MyFile.class)
  .to("bean:fileProcessor")
  .log("Downloaded file ${file:name} complete.");

So the idea is I have an event (for example a direct or from a message queue) that has a " fileName " property, and then use the property to download/consume a file with that name from a ftp.

I believe the problem is to have from().from() in the same route, but the problem is if I leave the ftp component inside a "to", then my queue event will be written into a file in the ftp, which is the opposite from what I want; it behaves as a produces instead of a consumer.

Is there any possible way to achieve what I'm trying to do or does it conflict with what Camel is for?

Thanks to the comment from Claus Ibsen I found what I was looking for, the component I needed and wich made it work was the Content Enricher .

Here is the route that worked for me:

from("direct:processFile")
  .pollEnrich().simple("ftp://localhost:21/folder?fileName=${body.fileName}")
  .log("Start downloading file ${file:name}.")
  .unmarshal().bindy(BindyType.Csv, MyFile.class)
  .to("bean:fileProcessor")
  .log("Downloaded file ${file:name} complete.");

How about something like this ?

  .from("direct:processFile")
  .transform(simple("${body.fileName}"))
  .from("ftp://localhost:21/folder?fileName=${body.fileName}") // etc.
  .log("Start downloading file ${file:name}.")
  .unmarshal().bindy(BindyType.Csv, MyFile.class)
  .to("bean:fileProcessor")
  .log("Downloaded file ${file:name} complete.");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM