blob: 90ddc3dbc6311fc33c91ec0643550707fdd40f6d [file] [log] [blame]
# Camel-Kafka-connector RabbitMQ Source
## Introduction
This is an example for Camel-Kafka-connector RabbitMQ
## What is needed
- A RabbitMQ instance
## Running Kafka
```
$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
```
## 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-rabbitmq-kafka-connector/0.9.0/camel-rabbitmq-kafka-connector-0.9.0-package.tar.gz
> untar.gz camel-rabbitmq-kafka-connector-0.9.0-package.tar.gz
```
## Setting up RabbitMQ
This examples require a running RabbitMQ instance, for simplicity the steps below show how to start RabbitMQ using Docker. First you'll need to run a RabbitMQ with management instance:
[source,bash]
----
docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3-management
----
Next, we need to check the address of the container
[source,bash]
----
> docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_id
172.17.0.2
----
In the configuration `.properties` file we use below the IP address of the RabbitMQ master node needs to be configured, replace the value `172.17.0.2` configuration property with the IP of the node obtained from Docker.
Next through your browser go to http://<address>:15672
and login with the credentials guest/guest
Create a queue called 'queue'.
Now it's time to setup the connectors
Open the RabbitMQ Source configuration file
```
name=CamelRabbitmqSourceConnector
connector.class=org.apache.camel.kafkaconnector.rabbitmq.CamelRabbitmqSourceConnector
key.converter=org.apache.kafka.connect.storage.StringConverter
value.converter=org.apache.kafka.connect.converters.ByteArrayConverter
camel.source.maxPollDuration=10000
topics=mytopic
camel.component.rabbitmq.hostname=172.17.0.2
camel.component.rabbitmq.portnumber=5672
camel.source.path.exchangeName=queue
camel.source.endpoint.exchangeType=topic
camel.source.endpoint.autoDelete=false
camel.source.endpoint.queue=queue
camel.source.endpoint.routingKey=key
```
Now you can run the example
```
$KAFKA_HOME/bin/connect-standalone.sh $KAFKA_HOME/config/connect-standalone.properties config/CamelRabbitmqSourceConnector.properties
```
At this point you should be able to publish messages through the management console, so these are the steps needed:
- Go to http://<address>:15672
- Select the Queues tab
- Select the 'queue' Queue
- Publish message with body "Hello"
On a different terminal run the kafka-consumer and you should see messages to Kafka from RabbitMQ
```
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mytopic --from-beginning
Hello
```