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/08/06 07:24:03 UTC

[camel-kafka-connector-examples] 01/01: Added a camel-nats source connector example

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

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

commit 23ca85b8b344bac12177a5fd734dcee6d0730bef
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Aug 6 09:23:31 2020 +0200

    Added a camel-nats source connector example
---
 nats/nats-source/README.adoc                       | 88 ++++++++++++++++++++++
 .../config/CamelNatsSourceConnector.properties     | 28 +++++++
 2 files changed, 116 insertions(+)

diff --git a/nats/nats-source/README.adoc b/nats/nats-source/README.adoc
new file mode 100644
index 0000000..a8f7fd6
--- /dev/null
+++ b/nats/nats-source/README.adoc
@@ -0,0 +1,88 @@
+# Camel-Kafka-connector NATS Source
+
+## Introduction
+
+This is an example for Camel-Kafka-connector NATS Source 
+
+## What is needed
+
+- A NATS topic
+
+## 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-nats-kafka-connector/0.4.0/camel-nats-kafka-connector-0.4.0-package.zip
+> unzip camel-nats-kafka-connector-0.4.0-package.zip
+```
+
+In this example we'll use a docker image for NATS
+
+```
+> docker run -d --name nats-main -p 4222:4222 -p 6222:6222 -p 8222:8222 nats
+```
+
+We'll need to inspect the container for the IP address of NATS 
+
+```
+> docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nats-main
+172.17.0.2
+```
+
+Now it's time to setup the connectors
+
+Open the NATS configuration file
+
+```
+name=CamelNatsSourceConnector
+connector.class=org.apache.camel.kafkaconnector.nats.CamelNatsSourceConnector
+key.converter=org.apache.kafka.connect.storage.StringConverter
+value.converter=org.apache.kafka.connect.converters.ByteArrayConverter
+
+camel.source.maxPollDuration=10000
+
+topics=mytopic
+
+camel.component.nats.servers=172.17.0.2
+camel.source.path.topic=nats-main
+```
+
+And add the correct address for the server.
+
+Now you can run the example
+
+```
+$KAFKA_HOME/bin/connect-standalone.sh $KAFKA_HOME/config/connect-standalone.properties config/CamelNatsSourceConnector.properties
+```
+
+To produce messages to NATS you can use nats-pub go executable
+
+```
+> go get github.com/nats-io/go-nats-examples/tools/nats-pub
+> nats-pub nats-main 'Kafka message'
+Published [nats-main] : 'Kafka message'
+```
+
+On a different terminal run the kafka-consumer and get messages
+
+```
+> bin/kafka-console-consumer.sh --topic mytopic --from-beginning --bootstrap-server localhost:9092
+Kafka message
+```
+
diff --git a/nats/nats-source/config/CamelNatsSourceConnector.properties b/nats/nats-source/config/CamelNatsSourceConnector.properties
new file mode 100644
index 0000000..f1afddd
--- /dev/null
+++ b/nats/nats-source/config/CamelNatsSourceConnector.properties
@@ -0,0 +1,28 @@
+#
+# 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=CamelNatsSourceConnector
+connector.class=org.apache.camel.kafkaconnector.nats.CamelNatsSourceConnector
+key.converter=org.apache.kafka.connect.storage.StringConverter
+value.converter=org.apache.kafka.connect.converters.ByteArrayConverter
+
+camel.source.maxPollDuration=10000
+
+topics=mytopic
+
+camel.component.nats.servers=172.17.0.2
+camel.source.path.topic=nats-main