Integration / Apache Camel Interview Questions
How does the Camel File component work for polling and processing files?
The camel-file component polls a directory for new files and processes each one as a Camel Exchange. The file body defaults to a java.io.File or InputStream depending on configuration. After processing, the file can be moved, deleted, or left in place based on the move, delete, and noop options.
// Poll, process, and move to done/ on success:
from("file:/data/in?move=done&moveFailed=failed&readLock=changed")
.log("Processing: ${header.CamelFileName}")
.unmarshal().csv()
.split(body())
.to("jms:queue:order-items")
.end();
// Write a file from a route:
from("direct:writeReport")
.setHeader(Exchange.FILE_NAME, simple("report-${date:now:yyyyMMdd}.csv"))
.to("file:/data/out");Key file component options: noop=true (leave file; for testing), delete=true (delete after read), move=dirname (move to subdirectory), readLock=changed (wait until file stops growing), delay=ms (polling interval), include=regex (file name filter), sortBy=filename (processing order). The component sets the CamelFileName and CamelFileLastModified headers automatically.
More Related questions...