Listen to a Folder

Introduction
In this hands-on workshop, you will build a file monitoring integration using Kaoto’s visual designer and Apache Camel. You’ll learn how to watch a directory for file system changes, filter events based on conditions, and automatically back up files when they are created.
What You’ll Learn:
- File system monitoring with the
file-watchcomponent - Extracting metadata from Camel message headers
- Filtering events using the Message Filter pattern
- Copying files to backup locations
- Testing and debugging Camel routes locally
- Using Apache Camel’s Simple Expression Language
What You’ll Build: A Camel route that monitors a directory for file changes, filters CREATE events, backs up newly created files to a separate directory, and logs all file system events to the console.
Prerequisites
Before starting this workshop, ensure you have the following installed and configured on your system:
Required Software
- Visual Studio Code - Download from code.visualstudio.com
- Kaoto Extension for VSCode - Install from the VSCode Marketplace
- Java Development Kit (JDK) 17 or later - Required for running Apache Camel
- Download from Adoptium or your preferred JDK distribution
- Apache Camel JBang - For easy infrastructure setup
- Install via:
curl -Ls https://sh.jbang.dev | bash -s - trust add https://github.com/apache/camel - Then:
jbang app install camel@apache/camel
- Install via:
Required Knowledge
This workshop assumes you have:
- Basic understanding of integration concepts - Familiarity with data processing
- Basic command-line skills - Ability to navigate directories and run commands
- Familiarity with VSCode - Basic navigation and file management
What You’ll Set Up During the Workshop
The following will be configured as part of the workshop steps:
- Test directories for file monitoring
- Backup directory for file copies
- Camel integration route
If you’re new to Kaoto or Apache Camel, this beginner workshop is the perfect starting point. It introduces core concepts progressively.
Project Setup
- Install the Kaoto extension for VSCode.
- Create a new directory for the workshop:
$ mkdir file-monitor-workshop
$ cd file-monitor-workshop
Windows users: This workshop was created in a Unix-based environment. While the commands shown should work in PowerShell, Command Prompt, and Git Bash, you may need to make adjustments accordingly. For example, if using Command Prompt, use md instead of mkdir, and adjust file paths to use Windows-style paths (e.g., C:\tmp\tutorial\ instead of /tmp/tutorial/).
Description
This workshop guides you through building a file monitoring integration using Apache Camel and Kaoto. You will create a route that demonstrates the File Integration Pattern and Message Filter Pattern, two fundamental Enterprise Integration Patterns (EIPs).
The Route Flow:
File System Events → File Watch → Filter (CREATE only) → Copy to Backup
↓
Log All Events
The route continuously monitors a directory, processes each file system event, filters for CREATE events to trigger backups, and logs all events for visibility.
Part 1: Log Changes
Goal
Create a route that watches a folder and logs file system events (CREATE, MODIFY, DELETE) with detailed information about each change.
Step-by-Step Instructions
Step 1: Create a New Route
- Open VSCode and navigate to your
file-monitor-workshopdirectory - Click the Kaoto icon in the left sidebar
- Click the Camel File… button to create a new integration

- If the Camel File… button is not showing, click on the second icon next to Integrations (a file with a + sign).
- In the dialog that appears:
- Select Camel Route as the file type
- Select YAML as the Camel DSL
- Choose your workshop folder as the saving location
- Name the file
file-monitor
A new route will appear in the Kaoto visual designer with a default timer component, a SetBody step and Log processor.

- Select Camel Main 4.16.0 from the options that appear when clicking the Camel version selector. This tutorial was created using this version and other versions have not been tested in this context. If chosen other Camel versions, they may present slight variations in component availability and presentation.

Step 2: Configure the File Watcher
The first component needs to monitor the test directory for file changes.
- Hover over the timer component in the visual designer
- Click the Replace icon (circular arrow) that appears

- In the search box, type
file-watchand select the File Watch component

- Click on the File Watch component to open its properties panel on the right
- Navigate to the All tab at the top of the properties panel
- Configure the following properties:
Property Value What it does path /tmp/tutorial/Directory to monitor for changes recursive falseDon’t watch subdirectories auto create trueCreates the directory automatically. True by default

- Save the file using
Ctrl/Cmd + Sor by clicking File → Save in the VS Code menu bar
Use the file-watch component, not the file component. The file-watch component monitors for file system events, while file is for reading file contents.
Step 3: Add Log Processor
Now we’ll add a log step to output information about detected changes.
Hover over the second component (SetBody) in the route
Click the Delete icon
Click on the Log processor to open its properties
Configure the message property in Required tab:
Property Value message Detected ${header.CamelFileEventType} on file ${header.CamelFileName} at ${header.CamelFileLastModified}Save the changes
💡 Understanding Camel Headers: The
file-watchcomponent populates message headers with metadata about file events:
CamelFileEventType: Type of event (CREATE, MODIFY, DELETE)CamelFileName: Name of the affected fileCamelFileLastModified: Timestamp of last modification
Step 4: Review Your Route
You can find the source code by clicking in the </> icon on the top right of the visual designer.

Your completed route should look like this in the visual designer. The YAML source should be similar to:
If your YAML doesn’t match exactly, you can copy and paste this code into the source editor. Kaoto will automatically update the visual designer.
✅ Checkpoint: You’ve completed Part 1! The route will now monitor the folder and log all file system events.
Part 2: Add a Filter
Goal
Enhance the route to filter events and only back up files when they are created (not modified or deleted). This introduces the Message Filter Pattern.
Step-by-Step Instructions
Step 1: Add Filter Processor
We’ll insert a filter between the file-watch and log components.
- Hover over the arrow between file-watch and log

- Click the + icon that appears on the arrow
- Search for
filterand select the Filter processor - Click on the Filter component to open its properties
- Configure the filter expression in Required tab:
Property Value What it does Expression language Simple The expression language to use Expression ${header.CamelFileEventType} == 'CREATE'Condition to evaluate

- Save the changes
💡 Understanding the Filter: The filter creates a conditional branch. Steps inside the filter only execute when the condition is true. In this case, only CREATE events will pass through.
Step 2: Add File Component Inside Filter
Now we’ll add a file component inside the filter to copy created files.
- Click inside the filter placeholder (the dotted box area)

This will add a new component inside the filter branch
Search for
fileand select the File componentClick on the File component to open its properties
Configure in Required tab:
Property Value What it does directoryName /tmp/backup/Destination folder for file copies auto create trueCreates the directory automatically. True by default Save the changes
The file component must be placed inside the filter. Use the “Insert into” context menu or click inside the filter placeholder to ensure proper nesting.
Step 3: Review Your Route
Your completed route should look like this in the visual designer. The YAML source should be similar to:
✅ Checkpoint: You’ve completed Part 2! The route now backs up files only when they are created, while still logging all events.
Part 3: Testing Your Route
Goal
Launch the route locally and verify it works correctly by creating, modifying, and deleting test files.
Step-by-Step Instructions
Step 1: Launch the Route
- In the VSCode file explorer, locate your
file-monitor-workshopfolder - In the Kaoto extension panel, find the folder containing your YAML route file
- Click the Play button (▶️) next to Integrations or next to the folder name


- A new terminal will open in VSCode
- Watch the terminal output as Camel JBang starts the route
You should see output similar to:
INFO [route-2573] Apache Camel 4.16.0 (file-monitor) started in ...
💡 What’s happening: The Kaoto extension uses Camel JBang to run your route locally, making it easy to test without complex setup.
Step 2: Test the Integration
With the route running, test it by creating files in the monitored directory:
- Open a new terminal window
- Create a test file:
$ echo "test content" > /tmp/tutorial/test1.txt
- Watch the Camel terminal for log output showing the CREATE event
- Verify the file was copied to
/tmp/backup/ - Try modifying the file:
$ echo "modified" >> /tmp/tutorial/test1.txt
- Watch for the MODIFY event in the logs (file won’t be copied again)
- Try deleting the file:
$ rm /tmp/tutorial/test1.txt
- Watch for the DELETE event in the logs
Step 3: Stop the Route
To stop the running integration:
- Go to the terminal where Camel is running
- Press
Ctrl + C
✅ Checkpoint: You’ve completed the workshop! You now understand file monitoring, filtering, and local testing with Kaoto.
Key Concepts Covered
Apache Camel Components
Components are the building blocks of Camel routes. They represent endpoints that can send or receive messages.
| Component | Purpose | Used In |
|---|---|---|
| file-watch | Monitors directories for file events | Part 1 |
| file | Reads from or writes to files | Part 2 |
Apache Camel Processors
Processors transform or manipulate messages as they flow through a route.
| Processor | Purpose | Used In |
|---|---|---|
| log | Outputs messages to console | Part 1 |
| filter | Conditionally executes steps | Part 2 |
Simple Expression Language
Camel’s Simple Expression Language is used for accessing message data and performing operations.
| Expression | What it accesses | Example |
|---|---|---|
${header.name} | Message header | ${header.CamelFileEventType} |
${header.CamelFileEventType} | File event type | CREATE, MODIFY, DELETE |
${header.CamelFileName} | File name | test1.txt |
${header.CamelFileLastModified} | Last modified timestamp | 2024-01-24T12:30:00 |
Enterprise Integration Patterns
This workshop demonstrates the Message Filter Pattern:
Message Filter - Selectively processes messages based on criteria. In this workshop, we filter file events to process only CREATE events for backup purposes.
Best Practices
Route Design
- Start simple: Begin with basic routes, add complexity gradually
- Use meaningful names: Name components and routes clearly
- Add descriptions: Use the description property to document components
- Test incrementally: Test after each major change
Component Selection
- Choose the right component: Understand component vs. processor differences
- Read documentation: Reference Apache Camel docs for details
- Configure properly: Fill all required parameters
- Use appropriate expressions: Match expression language to use case
Testing Strategy
- Verify prerequisites: Check installations before testing
- Create test data: Prepare files and directories
- Monitor output: Watch terminal for errors and results
- Iterate quickly: Make small changes and retest
Troubleshooting
- Check prerequisites: Verify Extension Pack and JBang installed
- Verify paths: Ensure directories exist and are accessible
- Review configuration: Double-check parameter values
- Read error messages: Camel provides detailed error information
Additional Resources
Documentation
- Kaoto Documentation - Kaoto user guide and tutorials
- Apache Camel Documentation - Complete Camel reference
- Apache Camel YAML DSL - YAML DSL reference
- Enterprise Integration Patterns - EIP reference
Community
- Kaoto GitHub - Report issues and contribute
- Apache Camel Community - Get help and connect with other users
