Try it out on OpenShift with Strimzi

You can use the Camel Kafka connectors also on Kubernetes and OpenShift with the Strimzi project. Strimzi provides a set of operators and container images for running Kafka on Kubernetes and OpenShift. The following example shows how to run it with Camel Kafka connectors on OpenShift.

Deploy Kafka and Kafka Connect

First we install the Strimzi operator and use it to deploy the Kafka broker and Kafka Connect into our OpenShift project. We need to create security objects as part of installation so it is necessary to switch to admin user. If you use Minishift, you can do it with the following command:

oc login -u system:admin

We will use OpenShift project myproject. It it doesn’t exist yet, you can create it using following command:

oc new-project myproject

If the project already exists, you can switch to it with:

oc project myproject

We can now install the Strimzi operator into this project:

oc apply -f

Next we will deploy a Kafka broker cluster and a Kafka Connect cluster and then create a Kafka Connect image with the Debezium connectors installed:

# Deploy a single node Kafka broker
oc apply -f

# Deploy a single instance of Kafka Connect with no plug-in installed
oc apply -f

Add Camel Kafka connector binaries

Strimzi uses Source2Image builds to allow users to add their own connectors to the existing Strimzi Docker images. We now need to build the connectors and add them to the image:

mvn clean package
oc start-build my-connect-cluster-connect --from-dir=./core/target/camel-kafka-connector-0.0.1-SNAPSHOT-package/share/java --follow

We should now wait for the rollout of the new image to finish and the replica set with the new connector to become ready. Once it is done, we can check that the CamelSinkConnector and CamelSourceConnector are available in our Kafka Connect cluster. Strimzi is running Kafka Connect in a distributed mode. We can use HTTP to interact with it. To check the available connector plugins, you can run the following command:

oc exec -i -c kafka my-cluster-kafka-0 -- curl -s http://my-connect-cluster-connect-api:8083/connector-plugins

You should see something like this:


Create connector instance

Now we can create some instance of a connector plugin - got example of the S3 connector:

oc exec -i -c kafka my-cluster-kafka-0 -- curl -X POST \
    -H "Accept:application/json" \
    -H "Content-Type:application/json" \
    http://my-connect-cluster-connect-api:8083/connectors -d @- <<'EOF'
  "name": "s3-connector",
  "config": {
    "connector.class": "org.apache.camel.kafkaconnector.CamelSourceConnector",
    "tasks.max": "1",
    "key.converter": "",
    "value.converter": "org.apache.camel.kafkaconnector.converters.S3ObjectConverter",
    "camel.source.kafka.topic": "s3-topic",
    "camel.source.url": "aws-s3://camel-connector-test?autocloseBody=false",
    "camel.source.maxPollDuration": 10000,
    "": "xxx",
    "": "xxx",
    "": "xxx"

You can check the status of the connector using

oc exec -i -c kafka my-cluster-kafka-0 -- curl -s http://my-connect-cluster-connect-api:8083/connectors/s3-connector/status

Check received messages

You can also run the Kafka console consumer to see the messages received from the topic:

oc exec -i -c kafka my-cluster-kafka-0 -- bin/ --bootstrap-server localhost:9092 --topic s3-topic --from-beginning