blob: 670914c446d7465b804f3cefc8f8662154a09916 [file] [log] [blame]
= Camel-Kafka-connector Git Source Consuming Branch
This is an example for Camel-Kafka-connector Git Source Consuming Branch
== Standalone
=== What is needed
- A local git repository
=== Running Kafka
[source]
----
$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
----
=== Download the connector package
Download the connector package tar.gz and extract the content to a directory. In this example we'll use `/home/oscerd/connectors/`
[source]
----
> cd /home/oscerd/connectors/
> wget https://repo1.maven.org/maven2/org/apache/camel/kafkaconnector/camel-git-kafka-connector/0.9.0/camel-git-kafka-connector-0.9.0-package.tar.gz
> untar.gz camel-git-kafka-connector-0.9.0-package.tar.gz
----
=== Configuring Kafka Connect
You'll need to set up 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:
[source]
----
...
plugin.path=/home/oscerd/connectors
...
----
=== Setup the git repository
We'll need a git repository at the beginning.
[source]
----
> mkdir -p /tmp/test_repo/
> cd /tmp/test_repo/
> git init
> touch test.txt
> git add test.txt
> git commit -a -m "first commit"
----
Now we are ready to go
=== Setup the connectors
Open the Git configuration file at `$EXAMPLES/git/git-source-branch/config/CamelGitSourceConnector.properties`
[source]
----
name=CamelGitSourceConnector
connector.class=org.apache.camel.kafkaconnector.git.CamelGitSourceConnector
tasks.max=1
key.converter=org.apache.kafka.connect.storage.StringConverter
value.converter=org.apache.kafka.connect.storage.StringConverter
topics=mytopic
camel.source.path.localPath=/tmp/test_repo/
camel.source.endpoint.type=branch
----
=== Running the example
Run the kafka connect with the Git Source connector:
[source]
----
$KAFKA_HOME/bin/connect-standalone.sh $KAFKA_HOME/config/connect-standalone.properties $EXAMPLES/git/git-source-branch/config/CamelGitSourceConnector.properties
----
On a different terminal run the kafkacat consumer
[source]
----
> ./kafkacat -b localhost:9092 -t mytopic -f 'Headers: %h Value: %s'
% Auto-selecting Consumer mode (use -P or -C to override)
Headers: CamelHeader.CamelGitBranchLeaf=refs/heads/master,CamelHeader.CamelGitBranchObjectId=13c428bca29cd813485855df649bea7e38342694,CamelProperty.CamelToEndpoint=direct://end?pollingConsumerBlockTimeout=0&pollingConsumerBlockWhenFull=true&pollingConsumerQueueSize=1000 Value: refs/heads/master
% Reached end of topic db26 [0] at offset 1
----
Now let's create a different branch
[source]
----
> cd /tmp/test_repo/
> git checkout -b test_repo
----
Getting back to the consumer terminal we should see something like
[source]
----
CamelHeader.CamelGitBranchLeaf=refs/heads/test_repo,CamelHeader.CamelGitBranchObjectId=184aae4d863144a1bea5de752cf2f2f1c9800d38,CamelProperty.CamelToEndpoint=direct://end?pollingConsumerBlockTimeout=0&pollingConsumerBlockWhenFull=true&pollingConsumerQueueSize=1000 Value: refs/heads/test_repo
% Reached end of topic mytopic [0] at offset 2
----