You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/10/19 16:59:05 UTC

[camel-kafka-connector-examples] branch master updated: Added File Watch source connector example

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-kafka-connector-examples.git


The following commit(s) were added to refs/heads/master by this push:
     new 60b44e0  Added File Watch source connector example
60b44e0 is described below

commit 60b44e03af0798a41ebc6a155af36b08b20fb077
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Oct 19 18:57:45 2020 +0200

    Added File Watch source connector example
---
 file-watch/file-watch-source/README.adoc           | 72 ++++++++++++++++++++++
 .../CamelFilewatchSourceConnector.properties       | 25 ++++++++
 2 files changed, 97 insertions(+)

diff --git a/file-watch/file-watch-source/README.adoc b/file-watch/file-watch-source/README.adoc
new file mode 100644
index 0000000..a3fe97f
--- /dev/null
+++ b/file-watch/file-watch-source/README.adoc
@@ -0,0 +1,72 @@
+# 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 config/zookeeper.properties
+$KAFKA_HOME/bin/kafka-server-start.sh 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.5.0/camel-file-watch-kafka-connector-0.5.0-package.zip
+> unzip camel-file-watch-kafka-connector-0.5.0-package.zip
+```
+
+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.
+
+NOTE: In the camel-file-watch component we fixed a little problem in showing the kind of event. It will be available in 3.7.0, so in CKC 0.7.0.
+
+```
+bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic mytopic
+Headers: CamelHeader.CamelFileAbsolute=true,CamelHeader.CamelFileAbsolutePath=/home/oscerd/test-file-watch/test.txt,CamelHeader.CamelFileLastModified=1603125050560,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?poll [...]
+% Reached end of topic mytopic [0] at offset 1
+```
+
+
diff --git a/file-watch/file-watch-source/config/CamelFilewatchSourceConnector.properties b/file-watch/file-watch-source/config/CamelFilewatchSourceConnector.properties
new file mode 100644
index 0000000..7b0355b
--- /dev/null
+++ b/file-watch/file-watch-source/config/CamelFilewatchSourceConnector.properties
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+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>