This is an example for Camel-Kafka-connector Git Source for consuming Commit
$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 tar.gz and extract the content to a directory. In this example we’ll use /home/oscerd/connectors/
> cd /home/oscerd/connectors/
> wget https://repo1.maven.org/maven2/org/apache/camel/kafkaconnector/camel-git-kafka-connector/0.10.0/camel-git-kafka-connector-0.10.0-package.tar.gz
> untar.gz camel-git-kafka-connector-0.10.0-package.tar.gz
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:
...
plugin.path=/home/oscerd/connectors
...
We’ll need a git repository at the beginning.
> 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
Open the Git configuration file at $EXAMPLES/git/git-source-commit/config/CamelGitSourceConnector.properties
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.branchName=master
camel.source.endpoint.type=commit
Run the kafka connect with the Git Source connector:
$KAFKA_HOME/bin/connect-standalone.sh $KAFKA_HOME/config/connect-standalone.properties $EXAMPLES/git/git-source-commit/config/CamelGitSourceConnector.properties
On a different terminal run the kafkacat consumer
> ./kafkacat -b localhost:9092 -t mytopic -f 'Headers: %h Value: %s'
% Auto-selecting Consumer mode (use -P or -C to override)
Headers: CamelHeader.CamelGitAuthorName=Andrea Cosentino,CamelHeader.CamelGitCommiterName=Andrea Cosentino,CamelHeader.CamelGitCommitTime=1604597964,CamelProperty.CamelToEndpoint=direct://end?pollingConsumerBlockTimeout=0&pollingConsumerBlockWhenFull=true&pollingConsumerQueueSize=1000 Value: first commit
% Reached end of topic mytopic [0] at offset 1
Now let’s commit something else
> cd /tmp/test_repo/
> touch test1.txt
> git add test1.txt
> git commit -a -m "second commit"
Getting back to the consumer terminal we should see something like
Headers: CamelHeader.CamelGitAuthorName=Andrea Cosentino,CamelHeader.CamelGitCommiterName=Andrea Cosentino,CamelHeader.CamelGitCommitTime=1609839093,CamelProperty.CamelToEndpoint=direct://end?pollingConsumerBlockTimeout=0&pollingConsumerBlockWhenFull=true&pollingConsumerQueueSize=1000 Value: second commit
% Reached end of topic mytopic [0] at offset 2