$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
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.5.0/camel-nats-kafka-connector-0.5.0-package.zip
> unzip camel-nats-kafka-connector-0.5.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