concept file in category camel

This is an excerpt from Manning's book Camel in Action.
These examples are real code, and they show how easily you can route files from a folder to a Java Message Service (JMS) queue. Because there’s a real programming language underneath, you can use the existing tooling support, such as code completion and compiler error detection, as illustrated in figure 1.3.
Figure 6.2 To autodiscover a component named “bean,” the component resolver searches for a file named “bean” in a specific directory on the classpath. This file specifies that the component class that will be created is
BeanComponent.![]()
Autodiscovery is the way the components that ship with Camel are registered. To discover new components, Camel looks in the META-INF/services/org/apache/camel/component directory on the classpath for files. Files in this directory determine the name of a component and the fully qualified class name.
Reading files
As you’ve seen in previous chapters, reading files with Camel is straightforward. Here’s a simple example:
public void configure() { from("file:data/inbox?noop=true").to("stream:out"); }This route reads files from the data/inbox directory and prints the contents of each to the console. The printing is done by sending the message to the
System.outstream, accessible by using the Stream component. As stated in table 6.3, thenoopflag tells Camel to leave the original files as is. This is a convenience option for testing, because it means that you can run the route many times without having to repopulate a directory of test files.

This is an excerpt from Manning's book Camel in Action.
The first example we’ll look at can be considered the “hello world” of integrations: routing files. Suppose you need to read files from one directory (data/inbox), process them in some way, and write the result to another directory (data/outbox). For simplicity, you’ll skip the processing, so your output will be merely a copy of the original file. Figure 1.2 illustrates this process.
Figure 7.2. To autodiscover a component named “bean”, the component resolver searches for a file named “bean” in a specific directory on the classpath. This file specifies that the component class that will be created is BeanComponent.
![]()
Autodiscovery is the way the components that ship with Camel are registered. In order to discover new components, Camel looks in the META-INF/services/org/apache/camel/component directory on the classpath for files. Files in this directory determine what the name of a component is and what the fully qualified class name is.
Table 7.3. Common URI options used to configure the File component
Option
Default value
Description
delay 500 Specifies the number of milliseconds between polls of the directory. recursive false Specifies whether or not to recursively process files in all subdirectories of this directory. noop false Specifies file-moving behavior. By default, Camel will move files to the .camel directory after processing them. To stop this behavior and keep the original files in place, set the noop option to true. fileName null Uses an expression to set the filename used. For consumers, this acts as a filename filter; in producers, it’s used to set the name of the file being written. fileExist Override Specifies what a file producer will do if the same filename already exists. Valid options are Override, Append, Fail, and Ignore. Override will cause the file to be replaced. Append adds content to the file. Fail causes an exception to be thrown. If Ignore is set, an exception won’t be thrown and the file won’t be written. delete false Specifies whether Camel will delete the file after processing. By default, Camel will not delete the file. move .camel Specifies the directory to which Camel moves files after it’s done processing them. include null Specifies a regular expression. Camel will process only those files that match this expression. exclude null Specifies a regular expression. Camel will exclude files based on this expression. Let’s first see how Camel can be used to read files.
As you’ve seen in previous chapters, reading files with Camel is pretty straightforward. Here’s a simple example:
public void configure() {
from("file:data/inbox?noop=true").to("stream:out");
}This route will read files from the data/inbox directory and print the contents of each to the console. The printing is done by sending the message to the System.out stream, accessible by using the Stream component. As stated in table 7.3, the noop flag tells Camel to leave the original files as is. This is a convenience option for testing, because it means that you can run the route many times without having to repopulate a directory of test files.