You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ankelee <an...@gmail.com> on 2010/03/02 15:27:16 UTC

Join two messages from two sources in zip archive.

I have a message (text file) routed in one direction a that among other
things holds an id. Then I have a bunch of text files in a directory, also
with id's. I want to match the message with the text file that holds the
corresponding id. I want to put those two files in a zip archive and store
them in a directory.

I'm thinking about using an aggregator or pollEnrich with a custom
AggregationStrategy that takes a batch of 2, and checks whether the input
has already been zipped, if yes then open ziparchive and add new entry, if
not then create zip archive and add entry. 

The problem seems similar to Listing 3.3 in Camel In Action but how do I
select with pollEnrich that I only want to consume one particular file
depending on the id inside and leave the rest?
-- 
View this message in context: http://old.nabble.com/Join-two-messages-from-two-sources-in-zip-archive.-tp27756477p27756477.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Join two messages from two sources in zip archive.

Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Mar 5, 2010 at 12:55 PM, ankelee <an...@gmail.com> wrote:
>
> Yeah that works. I would like to consume the file also, right now I'm just
> deleting it after I've gotten what I want from it. Is there a better
> solution?
> --

Yeah deleting the file is fine, as you are handling all the file stuff yourself.


> View this message in context: http://old.nabble.com/Join-two-messages-from-two-sources-in-zip-archive.-tp27756477p27793015.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Join two messages from two sources in zip archive.

Posted by ankelee <an...@gmail.com>.
Yeah that works. I would like to consume the file also, right now I'm just
deleting it after I've gotten what I want from it. Is there a better
solution?
-- 
View this message in context: http://old.nabble.com/Join-two-messages-from-two-sources-in-zip-archive.-tp27756477p27793015.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Join two messages from two sources in zip archive.

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Mar 2, 2010 at 3:27 PM, ankelee <an...@gmail.com> wrote:
>
> I have a message (text file) routed in one direction a that among other
> things holds an id. Then I have a bunch of text files in a directory, also
> with id's. I want to match the message with the text file that holds the
> corresponding id. I want to put those two files in a zip archive and store
> them in a directory.
>
> I'm thinking about using an aggregator or pollEnrich with a custom
> AggregationStrategy that takes a batch of 2, and checks whether the input
> has already been zipped, if yes then open ziparchive and add new entry, if
> not then create zip archive and add entry.
>
> The problem seems similar to Listing 3.3 in Camel In Action but how do I
> select with pollEnrich that I only want to consume one particular file
> depending on the id inside and leave the rest?

There is one limitation with pollEnrich, which is that it does not
support if the route is started from a file endpoint.
That kinda currently conflicts with the current codebase. There is a
JIRA ticket to enhance this in the future.

If you want to grab a file, then I suggest to use a Processor which
can easy do it like this

.process(new Processor()) {
  public void process(Exchange exchange) throws Exception {
     String filename = .... // you compute the file name to poll
     File file = new File(filename);
     // use the Camel type converters to load the file and return its
content as a String
     String fileBody =
exchange.getContext().getTypeConverter().convertTo(String.class,
file);
     // now you can merge that file body with the existing message on
Exchange.getIn().getBody
 }
}.to("your route continues here")




> --
> View this message in context: http://old.nabble.com/Join-two-messages-from-two-sources-in-zip-archive.-tp27756477p27756477.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus