blob: 08b8beeec889ced840fae74da3cd0b998fa0cdee [file] [log] [blame]
# Camel-Kafka-connector File Watch Source
This is an example for Camel-Kafka-connector File Watch Source
## Standalone
### What is needed
- A File System
### Running Kafka
```
$KAFKA_HOME/bin/zookeeper-server-start.sh $KAFKA_HOME/config/zookeeper.properties
$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties
$KAFKA_HOME/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic mytopic
```
## Setting up the needed bits and running the example
You'll need to setup the plugin.path property in your kafka
Open the `$KAFKA_HOME/config/connect-standalone.properties`
and set the `plugin.path` property to your choosen location
In this example we'll use `/home/oscerd/connectors/`
```
> cd /home/oscerd/connectors/
> wget https://repo1.maven.org/maven2/org/apache/camel/kafkaconnector/camel-file-watch-kafka-connector/0.11.5/camel-file-watch-kafka-connector-0.11.5-package.tar.gz
> untar.gz camel-file-watch-kafka-connector-0.11.5-package.tar.gz
```
Now it's time to setup the connectors
Open the File Watch configuration file
```
name=CamelFilewatchSourceConnector
connector.class=org.apache.camel.kafkaconnector.filewatch.CamelFilewatchSourceConnector
key.converter=org.apache.kafka.connect.storage.StringConverter
value.converter=org.apache.kafka.connect.storage.StringConverter
topics=mytopic
camel.source.path.path=<path_to_dir>
```
and add the correct directory to watch.
Now you can run the example
```
$KAFKA_HOME/bin/connect-standalone.sh $KAFKA_HOME/config/connect-standalone.properties config/CamelFileWatchSourceConnector.properties
```
Create some files into your directory of choice. For example we create the file test.txt in the directory /home/oscerd/test-file-watch/
Through kafkacat you should see the info coming in.
This component return all of the information as headers.
```
> ./kafkacat -b localhost:9092 -t mytopic -f 'Headers: %h Value: %s'
Headers: CamelHeader.CamelFileAbsolute=true,CamelHeader.CamelFileAbsolutePath=/home/oscerd/test-file-watch/test.txt,CamelHeader.CamelFileEventType=CREATE,CamelHeader.CamelFileLastModified=1609758044292,CamelHeader.CamelFileName=test.txt,CamelHeader.CamelFileNameConsumed=test.txt,CamelHeader.CamelFileNameOnly=test.txt,CamelHeader.CamelFileParent=/home/oscerd/test-file-watch,CamelHeader.CamelFilePath=/home/oscerd/test-file-watch/test.txt,CamelHeader.CamelFileRelativePath=test.txt,CamelProperty.CamelToEndpoint=direct://end?pollingConsumerBlockTimeout=0&pollingConsumerBlockWhenFull=true&pollingConsumerQueueSize=1000 Value: /home/oscerd/test-file-watch/test.txt
% Reached end of topic mytopic [0] at offset 1
```