1

When a SEDA component is consuming from a File component, what does the SEDA queue most closely resemble? Is it a List<File>? A List<String> of file paths?

1 Answer 1

3

I did this a while ago. In the file consumer the file is not actually loaded till you touch the body. The file path is passed in the header with some other variables. The body will contain a org.apache.camel.component.file.GenericFile object till you convert it. There will only be one file per message not a list of files.

Assuming this is text file you are working with if you had the following route:

<from uri="file:d:/Inbox?delay=5000&amp;move=.donebackup/placement/${date:now:yyyyMMdd}/${file:onlyname.noext}_DONE_${date:now:yyyyMMddHHmmss}.${file:name.ext}&amp;readLock=changed&amp;include=.*.dl&amp;maxMessagesPerPoll=0&amp;sortBy=${file:length}"/>
<convertBodyTo type="java.lang.String"/>
<log message="Converted File To String:${date:now:yyyy-MM-dd HH:mm:ss} handing data to File To DB route."/>
<to uri="seda:fileToDB"/>

Your body would contain strings. This is due to me converting the body from org.apache.camel.component.file.GenericFile to strings before sending it on the seda:fileToDB route.

However if you had:

<from uri="file:d:/Inbox?delay=5000&amp;move=.donebackup/placement/${date:now:yyyyMMdd}/${file:onlyname.noext}_DONE_${date:now:yyyyMMddHHmmss}.${file:name.ext}&amp;readLock=changed&amp;include=.*.dl&amp;maxMessagesPerPoll=0&amp;sortBy=${file:length}"/>
<to uri="seda:fileToDB"/>

The body would not be loaded thus the message body would be contain org.apache.camel.component.file.GenericFile on the seda:fileToDB route and only contain the file path in the header. Like I mentioned before the file is not loaded till you work with the body.

If you worked with a binary file you would load the body like this:

byte[] filedata = exchange.getIn().getBody(byte[].class);

The body would then contain a byte[].

If you did this File file = msg.getIn().getBody(File.class); the body would contain a file object.

So it depends on what you do with the body before the time. If you convert it to some appropriate data type it would contain that type otherwise it will be org.apache.camel.component.file.GenericFile

This link on camel contains some interesting examples.

Not the answer you're looking for? Browse other questions tagged or ask your own question.