File Watch Source
Provided by: "Apache Software Foundation"
Support Level for this Kamelet is: "Stable"
Sends a message each time a file in a local directory is created, changed or deleted, with the kind of change and the path of the file.
Use it to react to files that another program writes into a directory on the same machine, for example to start processing when a new export appears, or to keep track of the changes in a folder. To read files from a remote server instead, use ftp-source, sftp-source or aws-s3-source.
Output: the body is the file that changed, which the next step can read as text or bytes; a deleted file or a directory has no content to read. The CamelFileEventType header is CREATE, MODIFY or DELETE, CamelFileName is the path of the file relative to the watched directory, and CamelFileAbsolutePath is its full path.
Good to know: it watches the subdirectories too, new ones included, unless recursive is false. To send only the changes of some files, set antInclude. It never changes or deletes the files. Only changes made while it runs are sent, not the files that are already there when it starts. The path must be a directory, not a single file; it is created when it does not exist. On Kubernetes, mount the directory into the pod as a volume.
Configuration Options
The following table summarizes the configuration options available for the file-watch-source Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
Events | Required The kinds of change to send, as a comma-separated list of | string | CREATE,MODIFY,DELETE | CREATE | |
Directory to Watch | Required The full path of the local directory to watch. It must be a directory, not a single file: to follow one file, watch its directory. Changes in its subdirectories are sent too, unless | string | /data/incoming | ||
Include Files (Wildcards) | A wildcard pattern that the path of a file must match for its changes to be sent, such as | string | */.csv | ||
Recursive | If true, the changes in the subdirectories of | boolean | true |
Dependencies
At runtime, the file-watch-source Kamelet relies upon the presence of the following dependencies:
-
camel:file-watch
-
camel:kamelet
Camel JBang usage
Prerequisites
-
You’ve installed JBang.
-
You have executed the following command:
jbang app install camel@apache/camel Supposing you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:file-watch-source"
parameters:
.
.
.
steps:
- to:
uri: "kamelet:log-sink" You can now run it directly through the following command
camel run route.yaml File Watch Source Kamelet Description
Configuration
The File Watch Source Kamelet monitors files or directories for changes and emits events when specific filesystem events occur. It requires the following configuration:
-
File Path: The path of the directory to monitor (required). It must be a directory, not a single file; it is created when it does not exist
-
Events: The types of filesystem events to watch for (default: "CREATE,MODIFY,DELETE")
-
Include Files (Wildcards): A wildcard pattern for the path of the files whose changes to send, such as
*/.csv(not set by default: all files) -
Recursive: Whether the changes in the subdirectories are sent too (default: true)
Event Types
The kamelet can monitor for the following types of filesystem events:
-
CREATE: Triggered when a new file or directory is created
-
MODIFY: Triggered when an existing file or directory is modified
-
DELETE: Triggered when a file or directory is deleted
You can specify multiple events by separating them with commas.
Output Format
The body of each message is the file that changed. The CamelFileEventType header holds the kind of event (CREATE, MODIFY or DELETE), CamelFileName the path relative to the watched directory, and CamelFileAbsolutePath the full path. Subdirectories are watched too, unless Recursive is false. A deleted file, or a directory, has no content to read.
Volume Mounting
When deployed on Kubernetes, this kamelet may require volume mounting to access the filesystem paths you want to monitor. Ensure the appropriate volumes are mounted to the pod running the integration.
Usage Example
- route:
from:
uri: "kamelet:file-watch-source"
parameters:
filePath: "/tmp/watched-directory"
events: "CREATE,MODIFY,DELETE"
steps:
- to:
uri: "kamelet:log-sink" Monitor Specific Events
- route:
from:
uri: "kamelet:file-watch-source"
parameters:
filePath: "/var/log/myapp"
events: "MODIFY"
steps:
- to:
uri: "kamelet:log-sink" This example only monitors for modifications of the files in the /var/log/myapp directory. To follow a single file, watch its directory and filter on CamelFileName.
Monitor Multiple Event Types
- route:
from:
uri: "kamelet:file-watch-source"
parameters:
filePath: "/home/user/documents"
events: "CREATE,DELETE"
steps:
- to:
uri: "kamelet:log-sink" This example monitors for file creation and deletion events in the documents directory.
Example with a File Pattern
- route:
from:
uri: "kamelet:file-watch-source"
parameters:
filePath: "/data/incoming"
events: "CREATE"
antInclude: "**/*.csv"
steps:
- to:
uri: "kamelet:log-sink" This sends a message for each new CSV file in /data/incoming and its subdirectories, and for no other file or directory. The pattern matches the path below filePath, such as 2026/orders.csv: matches any part of a name and * any number of directories, so *.csv alone matches only the files directly in /data/incoming. Upper and lower case differ. With recursive: false, only the changes directly in filePath are sent, which includes a new subdirectory itself but not the files in it.